简体   繁体   中英

Umbraco Examine - how to sort search results?

I am trying to sort my search results by a custom Umbraco property I have created - let's call it sortDate .

Inside my IndexSet, in config/ExamineIndex.config I have this:

<IndexUserFields>
        <add Name="sortDate" EnableSorting="true" Type="DateTime" />
        ...

In my Search user control, I am constructing a criteria and filter and using them to search like so:

var criteria =
      ExamineManager.Instance.SearchProviderCollection["MySearcher"].CreateSearchCriteria(
                UmbracoExamine.IndexTypes.Content);

var filter =
      criteria.GroupedOr(new string[] { "sortDate", "someThing", "someThingElse", "bodyText" }, SearchTerm.ToLower()).Compile();

var MySearchResults =
      ExamineManager.Instance.SearchProviderCollection["MySearcher"].Search(filter).Distinct();

I'm guessing I need to add something to specify how Lucene should sort this on my filter?

This is Umbraco 4.6.1 if that matters :)

好的,不确定我是如何错过这个的,但是看起来您可以做到:

filter.OrderBy( new string[] { "sortDate" } );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM