Reputation: 3361
We are using Couchbase 4.6.2 and trying to use the full text search feature. Our attempt is to search, sort, and paginate.
Currently, we have it indexed using the default index settings.
The issue we are running into is, when the FTS feature sorts the records, it sorts based on a single word in the field. Based on the documentation, it seems this is because of how full text search indexing works (and the analyzer that is chosen in the index). It takes each word and creates an index on that. Then when sorting is performed, it chooses either min or max values for that field and sorts on that value.
Is it possible to have the FTS index the fields on the per-word basis as it does now, but have the sort operate on the entire content of the property?
Upvotes: 2
Views: 234
Reputation: 121
The sorting operates using the terms in the index for the specified field. So, in order to sort on the entire value, you must use the keyword analyzer , since that keeps an entire field value as a single term. By using the keyword analyzer on that field, values like "Video Games" will be indexed as a single term.
Then if you specify that field for sorting, it will order by the entire value. Also, contrary to one of the other answers, the sorting operates on the indexed value, and does not require a stored value.
A related issue is that sometimes you want to search on the field as well as sort on it, and in this case you want to use an analyzer other than keyword. To accommodate both use cases, you simply have to index the field twice, once for searching and once for sorting. To do this, you simply have to give them different names. Something like 'category' for searching and 'category.sort' for sorting.
Upvotes: 5
Reputation: 41
you may try adding the "sort" option in your search request to explore the sorted ness of the results, eg: "sort" : ["fieldname"] for ascending and "sort": ["-fieldname"] for descending order. But for this, you need to enable the "store field"/"Store Dynamic Fields" during index creation.
Upvotes: 1