Microsoft Developer Network > Forums Home > Commerce Server Forums > Commerce Server 2009 > How could i sortby property1 ASC and property2 DESC in a catalog search?
Ask a questionAsk a question
 

AnswerHow could i sortby property1 ASC and property2 DESC in a catalog search?

  • Wednesday, October 21, 2009 4:29 PMMeng Yi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Wednesday, October 21, 2009 6:12 PMRavi Kanth KoppalaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.)
  • Wednesday, October 21, 2009 7:08 PMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Wednesday, October 21, 2009 6:12 PMRavi Kanth KoppalaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.)
  • Wednesday, October 21, 2009 7:08 PMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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
    •  
  • Thursday, October 22, 2009 2:56 AMRavi Kanth KoppalaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.)
  • Thursday, October 22, 2009 3:09 AMMeng Yi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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?
  • Thursday, October 22, 2009 4:56 AMMeng Yi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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!!!

  • Thursday, October 22, 2009 8:13 AMGael DuhamelMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It's a old trick from CS2000 :)
    http://gaelduhamel.spaces.live.com; http://www.twitter.com/GaelDuhamel; http://www.itcreme.com
  • Friday, October 23, 2009 11:47 AMMeng Yi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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....