API
Version 7.x > API > Smart Search Sorting View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/23/2013 3:58:52 PM
   
Smart Search Sorting
I've created a webpart that is a clone of the Smart Search Results which has an added dropdown (or radio button list) on the page and loads the searchable items by user input (public property exposed on the web part). I can get it to work with most of the items I have but some don't work and I wonder why.

I have a textarea that takes a value;name combination per line similar to how you'd populate a dropdown list on a biz form. I have the following entries:
##SCORE## DESC;Relevance (Highest)
##SCORE##;Relevance (Lowest)
documentcreatedwhen DESC;Date (Newest - Oldest)
documentcreatedwhen;Date (Oldest - Newest)
documentname;Name A-Z
documentname DESC;Name Z-A
Both dates work as expected, the Relevance (Highest) works and Name A-Z works but none of the others do. Is my syntax incorrect?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/1/2013 5:56:12 AM
   
RE:Smart Search Sorting
Hi,

So, the ones that don't work for you are the

documentname DESC;Name Z-A
and
##SCORE##;Relevance (Lowest)
and the other ones work? Is it possible to see it somewhere?

The Search sort field is defined as:

Defines the order in which search results are displayed. You can specify one or more document fields (separated by commas) according to which the results will be sorted. The ##SCORE## macro can be used to order results by their score (relevance). The default order is ascending, you can change this using the DESC keyword (e.g. articleid DESC). If you encounter the "field <fieldname> does not appear to be indexed" error when using multiple indexes, try specifying the type of the field using the following syntax: (date)createdwhen


Do you see any errors like described above?

Thank you in advance for information.
Best regards,
Zdenek

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/1/2013 7:42:14 AM
   
RE:Smart Search Sorting
Still in development on my machine yet and not published.

You are correct, the only 2 that aren't working are the ones you listed. I have not seen any errors in the error log or when debugging. I did follow the documentation and still receive weird results. I've even went as far as cutting back to one field vs. two for sorting.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/8/2013 9:29:50 AM
   
RE:Smart Search Sorting
Hi,

What exactly do you mean by cutting back to one field for sorting? Are you combining the settings for ORDER BY in code somewhere? Could you please describe it in more details?

By the way, which hotfix version have you applied to your CMS instance?

Thank you in advance for information.
Regards,
Zdenek.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/8/2013 1:54:42 PM
   
RE:Smart Search Sorting
Previously I had two fields to order by like so:
##SCORE##, documentcreatedwhen DESC
And I removed the documentcreatedwhen to see if results would change, which they didn't. I've simply created a textarea that allows a user to enter a single name/value pair per line and I parse it out and create dropdown items for each one. For instance:

##SCORE##;Relevance
documentcreatedwhen DESC;Create date
##SCORE##,documentcreatedwhen DESC;Relevance and create date

When I view the HTML code it is generating the values as expected and when I debug, its passing those exact values to the search function but just not sorting as expected.

I've developed and tested on a 7.0.40 version although it will be running on a 6.0.45 site. I've also tested the current fuctionality on both sites and they work exactly the same.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/18/2013 11:46:30 AM
   
RE:Smart Search Sorting
Hi,

Sorry for not getting back to you earlier. The thing is that the SearchSort is not added as a standard SQL query ORDER BY, it's processed by SearchHelper.GetSort() method and passed within the SearchParameters structure. The GetSort evaluates the input using the following RegExp:
"(?<type>\\(.*?\\))*\\s*(?<name>[^\\s]*)\\s*(?<order>.*)"
and the type, name and order are then processed to add the Lucene SortField object to a collection of sort fields. The fields have to be indexed but not tokenized, so you may try to review your doctypes search settings.

I'm still elaborating to get more information here, as it's more complex and "fancy" stuff.
Thank you for your cooperation and patience.

Regards,
Zdenek

User avatar
Certified Developer v6
Certified Developer v6
Dave - 8/1/2013 12:16:57 PM
   
RE:Smart Search Sorting
You can use the CMS.SiteProvider.SearchHelper.GetSort(string) method to turn a "FieldName DESC" type order string into the proper Lucene Sort object.

User avatar
Certified Developer v6
Certified Developer v6
Dave - 8/1/2013 12:18:22 PM
   
RE:Smart Search Sorting
Sorry Zdenek, just realized this is what you were explaining in your post. But I believe this is what FroggyEye is looking for.

User avatar
Member
Member
ewood-mgma - 12/18/2013 12:51:56 PM
   
RE:Smart Search Sorting
Hi FroggEye,

I know its been a few months since you first posted this question, but did you ever find a solution to your problem?

I'm using the Smart Search Filter, which follows a similar syntax for how you have set up sorting, trying to sort by documentname and that doesn't work, although sorting by score and documentcreatedwhen doe work. Sorting by documentpagetitle also doesn't work. There seems to be no rhyme or reason for when a field is sortable or not. At the very least it would be nice to get an error message from kentico if it perceives my sort filter to be garbage.

-Eddie

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/19/2013 2:07:51 AM
   
RE:Smart Search Sorting
Hello,

There is a reason. It depends how the particular fields are set - as for any other object, this applies for default/system fields too (search field settings).

In order to use DocumentName for sorting, you need to go to Site Manager -> Development -> System tables -> E-commerce SKU (yes, this table) -> Search fields. find the DocumentName field and set it to be "searchable" and uncheck "tokenized" - the field shall not be tokenized. Rebuild the index and it should do the trick.

Best regards,
Juraj Ondrus

User avatar
Member
Member
ewood-mgma - 12/19/2013 3:18:59 PM
   
RE:Smart Search Sorting
Thanks for the response! Duly noted.