Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 19, 2010 @ 15:44
    Ismail Mayat
    0

    Examine sort of results

    Hello,

    I have the following query

    var criteria = _searcher.CreateSearchCriteria(IndexTypes.Content);
    IBooleanOperation query = criteria.NodeTypeAlias("Product");
    //i add some dynamic stuff here
    query = query.And().OrderBy("nodeName");
    

    However the results still seem to be sorting by date added my results look like name then score i would expect an eco product to be the first one 

    • product 1 3.11619
    • product 3 3.11619
    • product 2 3.11619
    • product 4 3.11619
    • product 5 3.11619
    • product 7 3.11619
    • product 6 3.11619
    • an eco product 3.11619

     

    Regards

    Ismail

  • Lee 1130 posts 3088 karma points
    Aug 19, 2010 @ 16:10
    Lee
    0

    Sorry if this is a dumb question but I haven't used Examine yet, but what is Query (IEnumerable, List<T>) or something different?  

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 19, 2010 @ 17:35
    Ismail Mayat
    0

    Lee,

    Get stuck when trying with linq

    results.OrderBy(r=>r.Fields)

    its not complete basically the nodeName is a field in fields which is of type IDictionary<string,string> i got stuck any linq masters out there?

    regards

    Ismail

  • Lee 1130 posts 3088 karma points
    Aug 19, 2010 @ 18:13
    Lee
    0

    Ahhh ok that might explain why it wasn't finding nodeName if its in IDictionary<>?  

    Maybe something like (r=>r.Fields["nodeName"]) or (r=>r.Fields[0]) .. In fact I'm going to fire up VS and have a go because I'm probably way off! lol

  • Lee 1130 posts 3088 karma points
    Aug 19, 2010 @ 18:18
    Lee
    0

    Is it one or the other

     

    results.OrderBy(r=>r.Fields.Key[int])
    results.OrderBy(r=>r.Fields.Value[int])

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 20, 2010 @ 16:49
    Ismail Mayat
    0

    Lee,

    Ok got this sorted pardon the pun ;-}

     var sorted = from p in results
                             let nodeName = p.Fields["nodeName"]
                             orderby nodeName
                             select p;

    Put you down as solution as you give me the hint.  Its a work around as i am sorting using lucene but its not behaving!!!

    Regards

    Ismail

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 21, 2010 @ 08:50
    Aaron Powell
    2

    I'd advise against using LINQ to objects for sorting, you're loosing a huge amount in performance as all results have to be loaded from Lucene (which is costly).

    With your OrderBy statement in Examine you need to have enabled sorting on the field, see: http://examine.codeplex.com/wikipage?title=UmbracoExamine under IndexAttributeFields

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 23, 2010 @ 10:20
    Ismail Mayat
    0

    Slace,

    Awesome that works a treat. Just for my own understanding I notice that when you add the attribute EnableSorting="true" on a field it creates an extra field in the index and i guess you use that field namely _Sort_nodeName this is Indexed,Stored as opposed to nodeName which is additional Tokenised and term vector.  I take it if field is stored as tokenised and or term vector you cant sort on it hence duplicate field created?

    Regards

    Ismail

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 23, 2010 @ 10:24
    Aaron Powell
    0

    Correct, you can't sort on a tokenized field (well you can if there is only a single token ;)). Lucene has no idea which term in the field should be used for the sorting.

    Simplest way to get around this is to have an untokenized version of the field which you use for sorting (or so the initial research has shown us).

Please Sign in or register to post replies

Write your reply to:

Draft