How to sort search by a specific field?

Marcel Guldemond asked on June 12, 2017 17:13

We're using the API for searching, and it appears to be sorting using the DocumentModifiedWhen, even if the SearchSort param is set to a different field.

If we set the SearchSort param to "##SCORE## DESC" it seems to work, but other fields don't appear to be working.

If we set SearchSort = "sellingstylename ASC", it seems to sort for the first page and a bit, but not for the rest of the results.

Is the SearchSort parameter case sensitive? Do the other parameters like NumberOfProcessedResults affect how the resutls are sorted?

thanks, Marcel

Recent Answers

Trevor Fayas answered on June 13, 2017 00:12

Lucene's search index is a little bit tricky, it's not SQL syntax necessarily. Along with that, you need to make sure the order field you want to use is Searchable (checked).

Look to this page here by the "Search Sort" portion

It says you may need to specify the field type perhaps, but it looks like a string.

May want to download Luke 4.0 and use it to open your index and poke around at your data.

0 votesVote for this answer Mark as a Correct answer

Marcel Guldemond answered on June 14, 2017 16:31

Hi Trevor, thanks for your answer. Yes, the field is a string, and it was marked as Searchable, as well as Tokenized.

The issue appears to be that the Kentico search engine sorts by the tokenized fields, so some blocks of results were sorted by the first term, some by the last terms, and some didn't seem to have a discernible pattern. Sorting worked if I set the the field to not tokenized, and switched the index to Keyword, but then it's not very searchable because only exact matches returned results.

My solution was to create a duplicate of the column I wanted to sort by on the custom table to be used for sorting. The values are all the same as the first column, but while the first column is set to Tokenized (on) the duplicate is set to Tokenized (off)

Then I switched the index to Subset and set the code to sort by the second (untokenized) column.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.