Copied to clipboard

Flag this post as spam?

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


  • Mahgo 32 posts 152 karma points
    May 01, 2016 @ 09:40
    Mahgo
    0

    Examine OrderByDescending CreateDate not working

    One of the things I'm using Examine for is for retrieving the x most recent content for a particular nodetypealias. However, IQuery.OrderByDescending() on the "createDate" field does not seem to be working correctly, at least on dates.

    ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(IndexTypes.Content);
    IBooleanOperation query = searchCriteria.NodeTypeAlias("myAlias");
    query = query.And().OrderByDescending("createDate");
    ISearchResults results = searcher.Search(query.Compile(), max);
    

    For example, the nodes with these two dates:

    2016-04-26T20:17:46
    2016-05-01T18:54:05
    

    are always returned in that order.

    I'm using Umbraco 7.4.2

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    May 03, 2016 @ 09:16
    Ismail Mayat
    100

    Mahgo,

    See https://our.umbraco.org/forum/developers/api-questions/75407-how-in-gods-name-do-you-sort-by-date-using-examine

    I dont think modifying config will sort it but you can try however using document writing event to inject in sortable date will as I have done this.

    Regards

    Ismial

  • Mahgo 32 posts 152 karma points
    May 04, 2016 @ 07:47
    Mahgo
    1

    Thanks Ismail,

    Adding EnableSorting="true" to the particular field in IndexAttributeFields was what I needed to get it working!

Please Sign in or register to post replies

Write your reply to:

Draft