CoveoTopFieldSuggestions and sort with custom field
I try to implement a search with autocompletion.
In my results list, I sort by default with custom field like :
< CoveoTopFieldSuggestions data-sort-criteria="@mycustomfield ascending" />
To be consistent, I try to do the same thing with my CoveoTopFieldSuggestions components. The sort by default for this component is sortCriteria: occurences. I can't find how to replace it.
Is is possible to modify the sort by default for CoveoTopFieldSuggestions component ?
Unfortunately, no. This component triggers a query for a list of field in the index, not a standard query. If you read the documentation here, you will see the available sorts you can use. You cannot use your @customfield ascending/descending with those type of queries.
This is done because listing field values queries are faster then standard queries.
If you really wish to use the same sorting, you can instead try to hook your functions into the omnibox event(s) and do a real query to the index (using the REST API), then feed those results to the omnibox component. It's a bit more complicated, but should allow you to be more flexible.
If you have any questions on the best approach to use the framework to query the REST API, don't hesitate !
Ok great, thank you for your good answer !