How could i sortby property1 ASC and property2 DESC in a catalog search?
- Hi,
i know i can do
searchOptions.sortproperty="prop1, prop2";
searchOptions.sortDecending=true;//or searchOptions.sortAscending=true; which sorts both property in same order
but as in subject, How could i sortby property1 ASC and property2 DESC in a catalog search?
thanks.
Answers
- Check my blog to get the workaround for your problem.
http://microsoftblog.co.in/commerceserver/catalog-search-ascending-on-first-property-and-descending-on-second-property/
Hope this helps.
Regards,
-Ravi Kanth Koppala
http://techblog.ravikanth.net (If this post answers your question - Either Mark this post as the answer or vote as being useful.)- Proposed As Answer byRavi Kanth KoppalaMVPWednesday, October 21, 2009 6:12 PM
- Marked As Answer byMeng Yi Thursday, October 22, 2009 3:09 AM
Ravi,
You can sort different properties in different order in your search clause and avoid the dataview. Like that you can keep the benefit of the paging option for example and have better performance.
CatalogContext cc = CommerceContext.Current.CatalogSystem.CatalogContext;
CatalogSearch cs = cc.GetCatalogSearch();
cs.CatalogNames = "MyCatalog";
cs.SearchOptions.ClassTypes = CatalogClassTypes.ProductFamilyClass; // for example
cs.SearchOptions.PropertiesToReturn = "ProductId, cy_list_price";
cs.CategoriesClause = "CategoryName = 'CatId";
cs.SqlWhereClause = "Display = 'OK'";
cs.SearchOptions.SortProperty = "[ProductId]ASC, [cy_list_price]DESC";
The [ ] are very important!
http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com- Marked As Answer byMeng Yi Thursday, October 22, 2009 3:09 AM
- Proposed As Answer byGael DuhamelMVPWednesday, October 21, 2009 7:08 PM
All Replies
- Check my blog to get the workaround for your problem.
http://microsoftblog.co.in/commerceserver/catalog-search-ascending-on-first-property-and-descending-on-second-property/
Hope this helps.
Regards,
-Ravi Kanth Koppala
http://techblog.ravikanth.net (If this post answers your question - Either Mark this post as the answer or vote as being useful.)- Proposed As Answer byRavi Kanth KoppalaMVPWednesday, October 21, 2009 6:12 PM
- Marked As Answer byMeng Yi Thursday, October 22, 2009 3:09 AM
Ravi,
You can sort different properties in different order in your search clause and avoid the dataview. Like that you can keep the benefit of the paging option for example and have better performance.
CatalogContext cc = CommerceContext.Current.CatalogSystem.CatalogContext;
CatalogSearch cs = cc.GetCatalogSearch();
cs.CatalogNames = "MyCatalog";
cs.SearchOptions.ClassTypes = CatalogClassTypes.ProductFamilyClass; // for example
cs.SearchOptions.PropertiesToReturn = "ProductId, cy_list_price";
cs.CategoriesClause = "CategoryName = 'CatId";
cs.SqlWhereClause = "Display = 'OK'";
cs.SearchOptions.SortProperty = "[ProductId]ASC, [cy_list_price]DESC";
The [ ] are very important!
http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com- Marked As Answer byMeng Yi Thursday, October 22, 2009 3:09 AM
- Proposed As Answer byGael DuhamelMVPWednesday, October 21, 2009 7:08 PM
- Thanks it worked.
http://techblog.ravikanth.net (If this post answers your question - Either Mark this post as the answer or vote as being useful.) - it must be a GOOD day today.
The first thing in the morning i saw answers to my questions!
yes, i missed out the []. but no where is this stated in the documentation, isn't it? - for the benefit of the rest, not only the [] are important, you MUST NOT have space between ] and ASC or DESC. i.e.
"[ProductId]ASC, [cy_list_price]DESC"; //good
"[ProductId] ASC, [cy_list_price] DESC";//it breaks!!! - It's a old trick from CS2000 :)
http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com - now i got another tricky problem, how do i search those items with property1 = property2?
my scenario is that i have a long list of item with displayname=description, and recently we updated most of them to have a different displayname, and we wanted to delete those not updated (i.e. displayname=description).
i know it's simple to have just one pass through all the items to check and delete if desired, just to see if there is a better way....

