Copied to clipboard

Flag this post as spam?

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


  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 10, 2017 @ 08:47
    Dave Woestenborghs
    0

    Hi,

    I'm trying to order the results of my examine query.

    According to the docs this should be possible by adding it to the query : https://github.com/Shazwazza/Examine/wiki/Sorting-results

    But can't get it to work :

    I use this code in the document writing even of examine for adding a extra field to the index that I do the sorting on :

    if (e.Fields["nodeTypeAlias"] == "NewsDetailPage")
                {
                    DateTime sortDate;
    
                    if (e.Fields.ContainsKey("newsDate"))
                    {
                        sortDate = DateTime.Parse(e.Fields["newsDate"]);
                    }
                    else
                    {
                        sortDate = DateTime.Parse(e.Fields["createDate"]);
                    }
    
                    e.Document.Add(new Field("__newsSortDate", sortDate.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED));
                }
    

    This is based on this article : https://thecogworks.com/blog/posts/examiness-hints-and-tips-from-the-trenches-part-10-document-writing-redux/

    Then I do this to get my results, but they are not ordered by the sort date field :

    var searchCriteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria(IndexTypes.Content);
    
    var query = searchCriteria.Field("nodeTypeAlias", "NewsDetailPage").OrderByDescending("__newsSortDate");
    
    var results = ExamineManager.Instance.DefaultSearchProvider.Search(query.Compile());
    

    If I output the query I see this :

    { SearchIndexType: content, LuceneQuery: +(+nodeTypeAlias:newsdetailpage) +__IndexType:content }
    

    So no indication of sorting there.

    Any ideas on why this is happening. I can always sort the results themselves when I get them. But would be better to have them already sorted

    Umbraco 7.5.14 and Examine 0.1.82

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 10, 2017 @ 09:12
    Ismail Mayat
    1

    Dave,

    The sort part you will never see in the generated query as the sorting is done in bowels of lucene. After you implemented this code did you rebuild your index? Also can you show me screen grab of a record in the index using luke?

    Regards

    Ismail

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 10, 2017 @ 09:32
    Dave Woestenborghs
    0

    Hi,

    Ismail I rebuild the index several times. Also tried to remove __ in the field name.

    This what I see in Luke for the field :

    stored/uncompressed,indexed,tokenized<newsSortDate:20160216000000>
    

    Dave

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 10, 2017 @ 09:47
    Ismail Mayat
    0

    Dave,

    That looks ok. When injecting the field keep __ however in your query try

    OrderByDescending("newsSortDate")
    

    Does that work? Basically under the hood examine will use __

    If that dont work and if you have time can you jump on skype and show me whats going? Im on ismail_mayat

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 10, 2017 @ 10:17
    Dave Woestenborghs
    0

    Doesn't have any effect.

    Maybe will have a look again next week when I have more time.

    Dave

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 10, 2017 @ 10:26
    Dave Woestenborghs
    0

    I tried the same thing as described here in the unit test

    https://github.com/Shazwazza/Examine/blob/5999c711230b76db0a037120a8467eaf88eb8d9f/src/Examine.Test/Search/FluentApiTests.cs

    But that does not influence the order of the results as well

    Dave

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 10, 2017 @ 10:38
    Ismail Mayat
    0

    I say we leave it till uk fest and we can work through it, i can haz power to make it work lol. I have done it plenty of times

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    May 31, 2018 @ 07:50
    Ismail Mayat
    0

    Dave,

    You have in document writing event _newsSortDate change it to _Sort_newsDate then in your sort code just do .OrderByDescending("newsDate") that should work.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft