diff options
author | Robert Newson <rnewson@apache.org> | 2023-04-18 23:32:32 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2023-04-22 11:20:02 +0100 |
commit | 0366fe0640d867886b5916c1aab409c502d0823d (patch) | |
tree | 330ab8795ddb8927e37571d6513046e1eabd7823 | |
parent | 8aa5d44f33f437149154ff7b787cef77d09fa7cd (diff) | |
download | couchdb-0366fe0640d867886b5916c1aab409c502d0823d.tar.gz |
always facet, it improves sort performance
-rw-r--r-- | nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java | 22 | ||||
-rw-r--r-- | src/docs/src/api/ddoc/nouveau.rst | 11 | ||||
-rw-r--r-- | src/docs/src/ddocs/nouveau.rst | 26 | ||||
-rw-r--r-- | test/elixir/test/nouveau_test.exs | 4 |
4 files changed, 20 insertions, 43 deletions
diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java index 6908fe579..f4e048a39 100644 --- a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java +++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java @@ -79,6 +79,8 @@ import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.SearcherManager; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; +import org.apache.lucene.search.SortedNumericSortField; +import org.apache.lucene.search.SortedSetSortField; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopFieldCollector; @@ -348,19 +350,15 @@ public class Lucene9Index extends Index { sortString + " is not a valid sort parameter", Status.BAD_REQUEST); } final boolean reverse = "-".equals(m.group(1)); - SortField.Type type; switch (m.group(3)) { case "string": - type = SortField.Type.STRING; - break; + return new SortField(m.group(2), SortField.Type.STRING, reverse); case "double": - type = SortField.Type.DOUBLE; - break; + return new SortedNumericSortField(m.group(2), SortField.Type.DOUBLE, reverse); default: throw new WebApplicationException( m.group(3) + " is not a valid sort type", Status.BAD_REQUEST); } - return new SortField(m.group(2), type, reverse); } private static Document toDocument(final String docId, final DocumentUpdateRequest request) throws IOException { @@ -387,22 +385,18 @@ public class Lucene9Index extends Index { result.add(new org.apache.lucene.document.TextField(f.getName(), f.getValue(), f.isStore() ? Store.YES : Store.NO)); } else if (field instanceof StringField) { + // TODO use KeywordField when available. var f = (StringField) field; result.add(new org.apache.lucene.document.StringField(f.getName(), f.getValue(), f.isStore() ? Store.YES : Store.NO)); - if (f.isFacet()) { - result.add(new org.apache.lucene.document.SortedDocValuesField(f.getName(), - new BytesRef(f.getValue()))); - } + result.add(new org.apache.lucene.document.SortedDocValuesField(f.getName(), + new BytesRef(f.getValue()))); } else if (field instanceof DoubleField) { var f = (DoubleField) field; - result.add(new org.apache.lucene.document.DoublePoint(f.getName(), f.getValue())); + result.add(new org.apache.lucene.document.DoubleField(f.getName(), f.getValue())); if (f.isStore()) { result.add(new org.apache.lucene.document.StoredField(f.getName(), f.getValue())); } - if (f.isFacet()) { - result.add(new org.apache.lucene.document.DoubleDocValuesField(f.getName(), f.getValue())); - } } else if (field instanceof StoredField) { var f = (StoredField) field; var val = f.getValue(); diff --git a/src/docs/src/api/ddoc/nouveau.rst b/src/docs/src/api/ddoc/nouveau.rst index f885925e3..61f960322 100644 --- a/src/docs/src/api/ddoc/nouveau.rst +++ b/src/docs/src/api/ddoc/nouveau.rst @@ -43,16 +43,15 @@ confirming the end of the result list. :query json counts: An array of names of string fields for which counts are requested. The response contains counts for each unique value of this field - name among the documents that match the search query. :ref:`Faceting - <ddoc/nouveau/faceting>` must be enabled for this parameter to function. + name among the documents that match the search query. :query boolean include_docs: Include the full content of the documents in the response. :query number limit: Limit the number of the returned documents to the specified number. For a grouped search, this parameter limits the number of documents per group. :query string query: Required. The Lucene query string. - :query json ranges: This field defines ranges for faceted, numeric search fields. The - value is a JSON object where the fields names are faceted numeric search fields, + :query json ranges: This field defines ranges for numeric search fields. The + value is a JSON object where the fields names are numeric search fields, and the values of the fields are arrays of JSON objects. The objects must have a ``label``, ``min`` and ``max`` value (of type string, number, number respectively), and optional ``min_inclusive`` and ``max_inclusive`` properties (defaulting to @@ -86,10 +85,6 @@ :code 404: Specified database, design document or view is missed .. note:: - You must enable :ref:`faceting <ddoc/nouveau/faceting>` before you can use the - ``counts`` and ``ranges`` parameters. - -.. note:: Faceting is not supported on partitioned searches, so the following query parameters should not be used on those requests: ``counts`` and ``ranges``. diff --git a/src/docs/src/ddocs/nouveau.rst b/src/docs/src/ddocs/nouveau.rst index 7ea20e78d..94e88ed56 100644 --- a/src/docs/src/ddocs/nouveau.rst +++ b/src/docs/src/ddocs/nouveau.rst @@ -39,8 +39,7 @@ a document update. The ``index`` function takes the following parameters: If you set this parameter to ``default``, then this field is queried if no field is specified in the query syntax. #. Data that you want to index, for example, ``doc.address.country``. -#. (Optional) The third parameter includes the following fields: ``facet``, - and ``store``. These fields are described in more detail later. +#. (Optional) The third parameter includes the following field: ``store``. By default, a nouveau index response returns 25 rows. The number of hits that are returned can be changed by using the ``limit`` parameter. Each response includes a ``bookmark`` @@ -119,9 +118,6 @@ The ``index`` function takes four parameters, where the third parameter is optio *Index function (optional parameter)* - * **facet** - Creates a faceted index. See :ref:`Faceting <ddoc/search/faceting>`. - Values are ``true`` or ``false``. Default is ``false``. - * **store** - If ``true``, the value is returned in the search result; otherwise, the value is not returned. Values are ``true`` or ``false``. Default is ``false``. @@ -410,12 +406,6 @@ Query Parameters A full list of query parameters can be found in the :ref:`API Reference <api/ddoc/nouveau>`. -You must enable :ref:`faceting <ddoc/nouveau/faceting>` before you can use the -following parameters: - -- ``counts`` -- ``ranges`` - .. note:: Do not combine the ``bookmark`` and ``update`` options. These options constrain the choice of shard replicas to use for the response. When used @@ -588,17 +578,15 @@ Faceting Nouveau Search also supports faceted searching, enabling discovery of aggregate information about matches quickly and easily. You can match all documents by using the -special ``?q=*:*`` query syntax, and use the returned facets to refine your query. To -indicate that a field must be indexed for faceted queries, set ``{"facet": true}`` in its -options. +special ``?q=*:*`` query syntax, and use the returned facets to refine your query. -*Example of search query, specifying that faceted search is enabled:* +*Example of search query:* .. code-block:: javascript function(doc) { - index("string", "type", doc.type, {"facet": true}); - index("double", "price", doc.price, {"facet": true}); + index("string", "type", doc.type); + index("double", "price", doc.price); } To use facets, all the documents in the index must include all the fields that have @@ -614,8 +602,8 @@ using a single ``if`` statement. .. code-block:: javascript if (typeof doc.town == "string" && typeof doc.name == "string") { - index("string", "town", doc.town, {facet: true}); - index("string", "name", doc.name, {facet: true}); + index("string", "town", doc.town); + index("string", "name", doc.name); } Counts diff --git a/test/elixir/test/nouveau_test.exs b/test/elixir/test/nouveau_test.exs index ca2ae8eb4..06fcc4299 100644 --- a/test/elixir/test/nouveau_test.exs +++ b/test/elixir/test/nouveau_test.exs @@ -27,8 +27,8 @@ defmodule NouveauTest do default_analyzer: "standard", index: """ function (doc) { - index("string", "foo", doc.foo, {store: true, facet: true}); - index("double", "bar", doc.bar, {store: true, facet: true}); + index("string", "foo", doc.foo, {store: true}); + index("double", "bar", doc.bar, {store: true}); } """ } |