开发者

Umbraco Examine - how to sort search results?

开发者 https://www.devze.com 2023-02-16 07:35 出处:网络
I am trying to sort my search results by a custom Umbraco property I have created - let\'s call it sortDate.

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 :)


OK, not sure how I missed this, but it looks like you can just do:

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

精彩评论

暂无评论...
验证码 换一张
取 消