Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ben Grice 24 posts 176 karma points
    Apr 12, 2016 @ 12:53
    Ben Grice
    0

    Sorting descending with Examine

    I have looked at the documentation, but can't find anything definitive on how to sort descending by a field in Umbraco using Examine. (I can sort Ascending fine!). I'd like to sort by create Date, descending.... so this is what I have

      <IndexSet SetName="NewsAndPressCyIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/NewsAndPressCy/" IndexParentId="1052">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName" />
      <add Name="createDate" EnableSorting="true" Type="DateTime" />
      <add Name="path" />
    </IndexAttributeFields>
    <IndexUserFields>
      <add Name="articleHeadline" />
      <add Name="articleContent" />
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="NewsArticle" />
    </IncludeNodeTypes>
    <ExcludeNodeTypes>
    </ExcludeNodeTypes>
    

    And then in my c#

            string searchProviderCollection = Library.Languages.LanguageHelper.GetLanguageNameFromNodeId(Node.GetCurrent().Id) == "cy-GB" ? "NewsAndPressCySearcher" : "NewsAndPressEnSearcher";
    
            BaseSearchProvider searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProviderCollection];
            ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
            StringBuilder searchQueryString = new StringBuilder();
    
          ... build up search string etc etc etc
    
            ISearchCriteria searchQuery = searchCriteria.RawQuery(searchQueryString.ToString());//rderByDescending();//rderByDescending(new string[] { "createDate" });
            //searchQuery.OrderByDescending();
    
            ISearchResults searchResults = searcher.Search(searchQuery);//rderByDescending(x => x.Fields.["createDate"]);//
    

    Where do I specify that I would like to search Descending?

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 12, 2016 @ 16:56
    Ismail Mayat
    0

    Not sure you can set sort with raw query. I have done it with fluent api although i had to format the date using Document writing event see http://thecogworks.co.uk/blog/2013/04/11/examiness-hints-and-tips-from-the-trenches-part-10-document-writing-redux

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft