Copied to clipboard

Flag this post as spam?

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


  • David Armitage 508 posts 2077 karma points
    Aug 16, 2017 @ 10:22
    David Armitage
    0

    Umbraco Examine Lucene OrderBy Date

    Hi Guys,

    I am having a little trouble ordering the Examine.ISearchResults by a specified date fields.

    I looked at a lot of examples online and also some previous posts with similar issues but found no answers. Hopefully one of you can help.

    I have tried all these examples.

    criteria.OrderBy("expiryDate").Or();
    criteria.OrderBy("expiryDate[Type=DateTime]").Or();
    criteria.OrderBy(new[] { "expiryDate" }).Or();
    

    I have also added the field as a sortable field within the ExamineIndex.config

    <add Name="expiryDate" EnableSorting="true" Type="DateTime" />
    

    When I run the search it takes no notice of my ordering. Its almost like the standard sorting is overriding my stuff. The results are always following the order of the sortOrder field.

    The only way I have figured out how to sort of do this is by parsing the ISearchableResults as a List

    List<Examine.SearchResult> searchResultsList = searchResults.OrderBy(x => x.Fields["expiryDate"]).ToList();
    

    The problem with this is I think its a lot more speed expensive than it has to be. Following this I will be using paging so I don't need the whole data-set as a list. I only need 10 for example but I need then ordered before convert ToList() and .Skip() / .Take().

    Does anyone know the best way to OrderBy Date?

    Thanks in advance.

    Kind Regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft