Gravatar for

Question by kmelkez, May 30, 2014 3:37 PM

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 ?


2 Replies
Gravatar for

Answer by olamothe, May 30, 2014 3:57 PM

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.

Omnibox Component
Providing suggestions to the Omnibox

If you have any questions on the best approach to use the framework to query the REST API, don't hesitate !

Gravatar for

Answer by kmelkez, May 30, 2014 4:07 PM

Ok great, thank you for your good answer !

Gravatar for

Comment by olamothe, May 30, 2014 4:18 PM

Hey no problem ! Don't forget to "Accept" the answer, this will help other users that have a similar question to find an answer more easily.

Ask a question