Catalog Search – Ascending on first property and descending on second property
ravikanth | October 21, 2009Today I saw a forum post stating how can we achieve catalog search which has different sorting options on different properties, i.e., the user wants to have ascending order on one property and descending on second property at one shot. At the beginning I thought commerce server doesn’t support this feature but it does support with searchOptions (thanks for Gael). Commerce Server provides SearchOptions by which we can get search narrow down results (i.e, we can select the properties you want to return, number of rows, sort either descending or ascending, etc) in a single call.
Through SortProperty we can pass the properties name and order and make sure you keep property in [] braces. If you miss braces then you will receive “Search Failed” error. Here is the example where I am trying to fetch all products where the list price is greater than 10$ and the sorting on category name (desc), productId (asc) and variantId (desc).
|
CatalogContext context = CommerceContext.Current.CatalogSystem; // Specify the catalogs to search. // Return all items with price greater than $10.00. catalogSearch.SearchOptions = searchOptions; // Perform the search. |
Hello,
Very interesting post!
However, how does this kind of sorting take place? If first sorts the results based on the first criteria, and then, for those results
which are equal it applies the second criteria?
And a second question:
How do you obtain the search results based only on free text search ranking (without any other sorting option)
in CS 2009 extensibility kit (Microsoft.Commerce.Portal.SearchController.cs, public static List DoProductQuerySearch
Thank you in advance
I solved it!
For anyone interested to know.
FreeTextSearch_Rank is the property you need to add to the web part’s sort options.
You also need to add it in MetadataDefinitions.xml, among the properties.