Copied to clipboard

Flag this post as spam?

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


  • Brad 69 posts 97 karma points
    Feb 25, 2016 @ 22:36
    Brad
    1

    How in gods name do you sort by date using examine?

    I've probably been googling for hours, and no matter what I tried my custom date NEVER sorted from Examine. First I tried using GatheringNodeData and creating a value that was the date in long format. That didn't work, so I tried hooking into DocumentWriting and adding my own Lucene field. This included NumericField or just Field, but none of these ever work. I also tried using SortableField or just the string name when doing OrderBy, but this also never does anything. When I try sortOrder it always works from Lucene. I don't understand the different. I even tried splitting the date part up so it would be an Integer instead, but this also did nothing. I've used Luke to analyze what's being stored but can't come to any conclusions. How is this so hard?

    This is using the ExternalIndex.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 26, 2016 @ 00:26
    Marc Goodson
    0

    Hi Brad, what are your Examine Settings ?

    Have you got in your Examine ExternalIndexSet configuration:

    <IndexUserFields> <add Name="customDateField" EnableSorting="true" Type="DateTime" /> ... (other field names) ... </IndexUserFields>

    ie for the field you want to sort by you have identified the type, and set EnableSorting to true ?

    (you probably have, but just a sanity check)

    and Ismail wrote a blog post on injecting a sortable field using Document Writing, http://thecogworks.co.uk/blog/2013/04/11/examiness-hints-and-tips-from-the-trenches-part-10-document-writing-redux if that's worth comparing with what you have tried ?

    regards

    Marc

  • Brad 69 posts 97 karma points
    Feb 26, 2016 @ 15:55
    Brad
    0

    I'm actually using the default External index.

    Here is how I'm adding the field:

        Sub ExamineEvents_DocumentWriting(ByVal o As Object, ByVal e As DocumentWritingEventArgs)
        Dim doc = e.Document
    
        If (e.Fields.ContainsKey("displayDate")) Then
            Dim displayDate = CDate(e.Fields("displayDate"))
    
            Dim contentDate As String = displayDate.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture)
    
            Dim displayDateSort = New Field("__Sort_displayDate", contentDate, Field.Store.YES, Field.Index.NOT_ANALYZED)
    
            doc.Add(displayDateSort)
        End If
    
    End Sub
    

    And here is how I'm searching:

     Dim query = searchCriteria.GroupedOr(docType, docTypeValues).And().OrderByDescending({"__Sort_displayDate"}).Compile()
    

    Thank you,

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 26, 2016 @ 21:09
    Marc Goodson
    0

    Ahh the following didn't come through on my post above:

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

    in your examine settings: https://our.umbraco.org/documentation/Reference/Config/ExamineSettings/

    but your injecting of a sortable field via Document Writing event should also work and looking at your code (other than written in VB - it's been a while), looks correct - if you set a break point on your DocumentWriting event is it firing ?

    and do all the documents have a displayDate property ?, I'm wondering if you have a fall back to the date the node was created, to ensure the _SortdisplayDate field always gets added for each node, and always has a value...

  • Brad 69 posts 97 karma points
    Mar 02, 2016 @ 20:57
    Brad
    0

    Hi Marc,

    They definitely all have the field added through DocumentWriting. Take a look at my screenshot.enter image description here

    You're right I'm not using ExamineSettings I'm doing this from DocumentWriting.

    Not sure what to do.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Mar 04, 2016 @ 09:50
    Marc Goodson
    1

    Hi Brad

    I've knocked up a Sample project with latest Umbraco and Fanoe starter kit to replicate what you are doing.

    I get the same issue

    basically the DocumentWriting part (as you have it, and from the blog post) is all working fine, and as you can see from Luke, or from examine dashboard in Umbraco the new _SortdisplayDate field is getting added correctly to the index.

    However when I try to sort on it using the syntax:

      var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        ISearchCriteria criteria = searcher.CreateSearchCriteria();
         var result = criteria.GroupedOr(new string[] { "__NodeTypeAlias" }, "blogpost");
         result = result.And().OrderBy(new string[] {"__Sort_articleDate"});
        var searchResults = searcher.Search(result.Compile());
    

    The items are not sorted using the new _SortarticleDate

    but obviously if you write something like:

    @foreach (var item in searchResults.OrderByDescending(f=>f.Fields["__Sort_articleDate"]){
    

    then they are sorted correctly, so the values of _SortarticleDate are correct...

    However even if I sort by '__NodeId' or 'sortOrder' I'm finding that the results aren't sorted; so I think the issue likes in the .OrderBy clause rather than in the DocumentWriting code. very mysterious.

  • Brad 69 posts 97 karma points
    Mar 18, 2016 @ 17:48
    Brad
    0

    Anyone else have an idea? Should I open a bug report?

  • Brad 69 posts 97 karma points
    Mar 21, 2016 @ 18:03
    Brad
    0

    Still trying to get this working. It's so much slower to do the sort in .NET then it would be to do it in Lucene. Especially for 10,000+ records.

  • Brad 69 posts 97 karma points
    Mar 24, 2016 @ 13:55
    Brad
    1

    In case anyone has this problem, I rebuilt the examine index from the developer section and that appears to have fixed it.

  • Brad 69 posts 97 karma points
    Mar 29, 2016 @ 17:31
    Brad
    0

    Lol not to beat a dead horse, but that actually didn't fix it. I had to create my own external index, basically following "Examining Examine". Then on the date field I did EnableSorting and Type=DateTime.

    I think the issue is that the custom field added to the ExternalIndex wasn't vectorized for some reason, but I could be wrong.

  • Laurent Lequenne 123 posts 248 karma points
    May 04, 2017 @ 07:58
    Laurent Lequenne
    0

    Field.Index.NOT_ANALYZED :)

Please Sign in or register to post replies

Write your reply to:

Draft