Skip to content
This repository was archived by the owner on Oct 17, 2022. It is now read-only.

Commit e96c9e6

Browse files
lbboekocolosk
authored andcommitted
Add Search documentation (#418)
This adds a new User Guide for Search in the Design Documents section, and documents the various search-related endpoints in the API Reference. Co-authored-by: Lora Boe <lbboe@us.ibm.com>
1 parent 8cd4eff commit e96c9e6

File tree

9 files changed

+1309
-14
lines changed

9 files changed

+1309
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ ext/*.pyc
22
ext/__pycache__/
33
build/
44
venv
5+
.venv
6+
.DS_Store
57
*~
68
*.swp
79
*.bak

src/api/ddoc/common.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
The :method:`COPY` (which is non-standard HTTP) copies an existing design
8383
document to a new or existing one.
8484

85-
  Given that view indexes on disk are named after their MD5 hash of the
85+
Given that view indexes on disk are named after their MD5 hash of the
8686
view definition, and that a `COPY` operation won't actually change
8787
that definition, the copied views won't have to be reconstructed.
8888
Both views will be served from the same index on disk.

src/api/ddoc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ from your database.
3030
.. toctree::
3131
common
3232
views
33+
search
3334
render
3435
rewrites

src/api/ddoc/search.rst

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
2+
.. use this file except in compliance with the License. You may obtain a copy of
3+
.. the License at
4+
..
5+
.. http://www.apache.org/licenses/LICENSE-2.0
6+
..
7+
.. Unless required by applicable law or agreed to in writing, software
8+
.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
.. License for the specific language governing permissions and limitations under
11+
.. the License.
12+
13+
.. _api/ddoc/search:
14+
15+
=============================================
16+
``/db/_design/design-doc/_search/index-name``
17+
=============================================
18+
19+
.. versionadded:: 3.0
20+
21+
.. http:get:: /{db}/_design/{ddoc}/_search/{index}
22+
:synopsis: Returns results for the specified search index
23+
24+
Executes a search request against the named index in the specified design document.
25+
26+
:param db: Database name
27+
:param ddoc: Design document name
28+
:param index: Search index name
29+
30+
:<header Accept: - :mimetype:`application/json`
31+
- :mimetype:`text/plain`
32+
33+
:query string bookmark: A bookmark received from a previous search. This parameter
34+
enables paging through the results. If there are no more results after the
35+
bookmark, you get a response with an empty rows array and the same bookmark,
36+
confirming the end of the result list.
37+
:query json counts: An array of names of string fields for which counts
38+
are requested. The response contains counts for each unique value of this field
39+
name among the documents that match the search query. :ref:`Faceting
40+
<ddoc/search/faceting>` must be enabled for this parameter to function.
41+
:query json drilldown: This field can be used several times. Each use defines a pair
42+
with a field name and a value. The search matches only documents containing the
43+
value that was provided in the named field. It differs from using
44+
``"fieldname:value"`` in the ``q`` parameter only in that the values are not
45+
analyzed. :ref:`Faceting <ddoc/search/faceting>` must be enabled for this
46+
parameter to function.
47+
:query string group_field: Field by which to group search matches. :query number
48+
group_limit: Maximum group count. This field can be used only if ``group_field``
49+
is specified.
50+
:query json group_sort: This field defines the order of the groups in a search that
51+
uses ``group_field``. The default sort order is relevance.
52+
:query json highlight_fields: Specifies which fields to highlight. If specified, the
53+
result object contains a ``highlights`` field with an entry for each specified
54+
field.
55+
:query string highlight_pre_tag: A string that is inserted before the highlighted
56+
word in the highlights output.
57+
:query string highlight_post_tag: A string that is inserted after the highlighted
58+
word in the highlights output.
59+
:query number highlight_number: Number of fragments that are returned in highlights.
60+
If the search term occurs less often than the number of fragments that are
61+
specified, longer fragments are returned.
62+
:query number highlight_size: Number of characters in each fragment for highlights.
63+
:query boolean include_docs: Include the full content of the documents in the
64+
response.
65+
:query json include_fields: A JSON array of field names to include in search
66+
results. Any fields that are included must be indexed with the store:true option.
67+
:query number limit: Limit the number of the returned documents to the specified
68+
number. For a grouped search, this parameter limits the number of documents per
69+
group.
70+
:query string q: Alias for ``query``.
71+
:query string query: Required. The Lucene query string.
72+
:query json ranges: This field defines ranges for faceted, numeric search fields. The
73+
value is a JSON object where the fields names are faceted numeric search fields,
74+
and the values of the fields are JSON objects. The field names of the JSON objects
75+
are names for ranges. The values are strings that describe the range, for example
76+
"[0 TO 10]".
77+
:query json sort: Specifies the sort order of the results. In a grouped search (when
78+
``group_field`` is used), this parameter specifies the sort order within a group.
79+
The default sort order is relevance. A JSON string of the form
80+
``"fieldname<type>"`` or ``-fieldname<type>`` for descending order, where
81+
fieldname is the name of a string or number field, and ``type`` is either a
82+
number, a string, or a JSON array of strings. The ``type`` part is optional, and
83+
defaults to number. Some examples are ``"foo"``, ``"-foo"``, ``"bar<string>"``,
84+
``"-foo<number>"`` and [``"-foo<number>"``, ``"bar<string>"``]. String fields that
85+
are used for sorting must not be analyzed fields. Fields that are used for sorting
86+
must be indexed by the same indexer that is used for the search query.
87+
:query string stale: Set to ``ok`` to allow the use of an out-of-date index.
88+
89+
:>header Content-Type: - :mimetype:`application/json`
90+
- :mimetype:`text/plain; charset=utf-8`
91+
:>header ETag: Response signature
92+
:>header Transfer-Encoding: ``chunked``
93+
94+
:>json array rows: Array of view row objects. By default the information
95+
returned contains only the document ID and revision.
96+
:>json number total_rows: Number of documents in the database/view.
97+
:>json string bookmark: Opaque identifier to enable pagination.
98+
99+
:code 200: Request completed successfully
100+
:code 400: Invalid request
101+
:code 401: Read permission required
102+
:code 404: Specified database, design document or view is missed
103+
104+
.. note::
105+
You must enable :ref:`faceting <ddoc/search/faceting>` before you can use the
106+
``counts``, ``drilldown``, and ``ranges`` parameters.
107+
108+
.. note::
109+
Faceting and grouping are not supported on partitioned searches, so the following
110+
query parameters should not be used on those requests: ``counts``, ``drilldown``,
111+
``ranges``, and ``group_field``, ``group_limit``, group_sort``.
112+
113+
.. note::
114+
Do not combine the ``bookmark`` and ``stale`` options. These options constrain the
115+
choice of shard replicas to use for the response. When used together, the options
116+
might cause problems when contact is attempted with replicas that are slow or not
117+
available.
118+
119+
.. warning::
120+
Search requests will fail unless the CouchDB server is connected to a functioning
121+
Clouseau instance.
122+
123+
.. seealso::
124+
For more information about how search works, see the
125+
:ref:`Search User Guide<ddoc/search>`.
126+
127+
==================================================
128+
``/db/_design/design-doc/_search_info/index-name``
129+
==================================================
130+
131+
.. versionadded:: 3.0
132+
133+
.. http:get:: /{db}/_design/{ddoc}/_search_info/{index}
134+
:synopsis: Returns metadata for the specified search index
135+
136+
:param db: Database name
137+
:param ddoc: Design document name
138+
:param index: Search index name
139+
:code 200: Request completed successfully
140+
:code 400: Request body is wrong (malformed or missing one of the mandatory fields)
141+
:code 500: A server error (or other kind of error) occurred
142+
143+
**Request**:
144+
145+
.. code-block:: http
146+
147+
GET /recipes/_design/cookbook/_search_info/ingredients HTTP/1.1
148+
Accept: application/json
149+
Host: localhost:5984
150+
151+
**Response**:
152+
153+
.. code-block:: javascript
154+
155+
{
156+
"name": "_design/cookbook/ingredients",
157+
"search_index": {
158+
"pending_seq": 7125496,
159+
"doc_del_count": 129180,
160+
"doc_count": 1066173,
161+
"disk_size": 728305827,
162+
"committed_seq": 7125496
163+
}
164+
}

src/api/ddoc/views.rst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,9 @@ issues. These include:
270270
- Create the view definition (and associated design documents) on your database
271271
before allowing insertion or updates to the documents. If this is allowed
272272
while the view is being accessed, the index can be updated incrementally.
273-
274273
- Manually force a view request from the database. You can do this either
275274
before users are allowed to use the view, or you can access the view manually
276275
after documents are added or updated.
277-
278276
- Use the :ref:`changes feed <api/db/changes>` to monitor for changes to the
279277
database and then access the view to force the corresponding view index to be
280278
updated.
@@ -320,17 +318,25 @@ sequence exposed in the database information (returned by :get:`/{db}`).
320318
Sorting Returned Rows
321319
=====================
322320

323-
Each element within the returned array is sorted using native UTF-8 sorting
324-
according to the contents of the key portion of the emitted content. The basic
321+
Each element within the returned array is sorted using
322+
native UTF-8 sorting
323+
according to the contents of the key portion of the
324+
emitted content. The basic
325325
order of output is as follows:
326326

327-
- ``null``
328-
- ``false``
329-
- ``true``
330-
- Numbers
331-
- Text (case sensitive, lowercase first)
332-
- Arrays (according to the values of each element, in order)
333-
- Objects (according to the values of keys, in key order)
327+
- ``null``
328+
329+
- ``false``
330+
331+
- ``true``
332+
333+
- Numbers
334+
335+
- Text (case sensitive, lowercase first)
336+
337+
- Arrays (according to the values of each element, in order)
338+
339+
- Objects (according to the values of keys, in key order)
334340

335341
**Request**:
336342

@@ -455,8 +461,8 @@ order of output is as follows:
455461
"total_rows": 17
456462
}
457463
458-
You can reverse the order of the returned view information by using the
459-
``descending`` query value set to true:
464+
You can reverse the order of the returned view information
465+
by using the ``descending`` query value set to true:
460466

461467
**Request**:
462468

src/api/server/common.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,49 @@ containing only the requested individual statistic.
15171517

15181518
:code 200: Request completed successfully
15191519

1520+
.. _api/server/search_analyze:
1521+
1522+
==========================================
1523+
``/_search_analyze``
1524+
==========================================
1525+
1526+
.. versionadded:: 3.0
1527+
1528+
.. http:post:: /_search_analyze
1529+
:synopsis: Tests the results of analyzer tokenization
1530+
1531+
Tests the results of Lucene analyzer tokenization on sample text.
1532+
1533+
:param field: Type of analyzer
1534+
:param text: Analyzer token you want to test
1535+
:code 200: Request completed successfully
1536+
:code 400: Request body is wrong (malformed or missing one of the mandatory fields)
1537+
:code 500: A server error (or other kind of error) occurred
1538+
1539+
**Request**:
1540+
1541+
.. code-block:: http
1542+
1543+
POST /_search_analyze HTTP/1.1
1544+
Host: localhost:5984
1545+
Content-Type: application/json
1546+
1547+
{"analyzer":"english", "text":"running"}
1548+
1549+
**Response**:
1550+
1551+
.. code-block:: javascript
1552+
1553+
{
1554+
"tokens": [
1555+
"run"
1556+
]
1557+
}
1558+
1559+
.. warning::
1560+
Requests to this endpoint will fail unless the CouchDB server is connected to a
1561+
functioning Clouseau instance.
1562+
15201563
.. _api/server/utils:
15211564

15221565
===========

src/config/query-servers.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,43 @@ Native Erlang Query Server
187187

188188
Additional examples are on the `users@couchdb.apache.org mailing list
189189
<https://lists.apache.org/thread.html/9b5f2837bd32189385bb82eee44aec243f2ecacc6e907ffe0e1e03d3@1360091211@%3Cuser.couchdb.apache.org%3E>`_.
190+
191+
Search
192+
======
193+
194+
CouchDB's search subsystem can be configured via the ``dreyfus`` configuration section.
195+
196+
.. config:section:: dreyfus :: Search Subsystem Configuration
197+
198+
.. config:option:: name :: Clouseau JVM node name and location
199+
200+
The name and location of the Clouseau Java service required to enable Search
201+
functionality. Defaults to ``clouseau@127.0.0.1``.
202+
203+
.. config:option:: retry_limit :: Maximum number of connection retries
204+
205+
CouchDB will try to reconnect to Clouseau using a bounded exponential backoff with
206+
the following number of iterations. Defaults to ``5``.
207+
208+
.. config:option:: limit :: Default result set limit for global search
209+
210+
The number of results returned from a global search query if no limit is
211+
specified. Defaults to ``25``.
212+
213+
.. config:option:: limit_partitions :: Default result set limit for partitioned DBs
214+
215+
The number of results returned from a search on a partition of a database if no
216+
limit is specified. Defaults to ``2000``.
217+
218+
.. config:option:: max_limit :: Maximum result set for global search
219+
220+
The maximum number of results that can be returned from a global search query (or
221+
any search query on a database without user-defined partitions). Attempts to set
222+
``?limit=N higher`` than this value will be rejected. Defaults to ``200``.
223+
224+
.. config:option:: max_limit_partitions :: Maximum result set for partitioned search
225+
226+
The maximum number of results that can be returned when searching a partition of a
227+
database. Attempts to set ``?limit=N`` higher than this value will be rejected. If
228+
this config setting is not defined, CouchDB will use the value of ``max_limit``
229+
instead. If neither is defined, the default is ``2000``.

src/ddocs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ replications.
2626

2727
ddocs
2828
views/index
29+
search
2930

3031
*Note*: Previously, the functionality provided by CouchDB's design documents,
3132
in combination with document attachments, was referred to as "CouchApps." The

0 commit comments

Comments
 (0)