Problem: the cbft will return to me a sorted result only when giving the Descending
option a true
value, for some reason when giving false
it is not sorted (seems to be sorted based on updated
but not the field I am looking for.
Here is my code:
var (
qus []cbft.FtsQuery
)
...
conjunction := cbft.NewConjunctionQuery(qus...)
q := gocb.NewSearchQuery(dd.Config.TrialsSearchIndex, conjunction)
sortBy := cbft.NewSearchSortField("drug_name").Descending(true) // if false does not sort
q.Sort(sortBy)
res, err := dd.Couchbase.TrialsBucket.ExecuteSearchQuery(q)
Why won't it sort in ascending order?
Turns out that the issue was with the way the field was being parsed, Couchbase allows placing custom analyzers on a field, if you need to use the same field in a text search where say you need to parse multiple words and in a case like here just retrieving in Alphabetical order you will need to define an alias on the field and put a different analyzer for that field. In this case I set the anlyzer to "single" (i.e. to parse the field as ONE word) and to filter everything as to be lowercase insensitive.
Basically create an alias for the field
field_sort
and a custom analyzer. You can read more about writing analyzers here: https://docs.couchbase.com/server/current/fts/fts-using-analyzers.html The documentation leaves what to be desired but hopefully this helps someone.