Copied to clipboard

Flag this post as spam?

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

  • Simon Yohannes 58 posts 188 karma points
    Sep 06, 2010 @ 19:06
    Simon Yohannes

    examine vs luke

    when searching a field that contains the text "touchpad mouse brilliant", in luke, the order in which i have these words in the query doesn't matter - it always returns matches.

    in umbraco, unless i match the word order exactly, i.e. "touchpad mouse brilliant", nothing will be returned. to give you an example of what would fail: "brilliant mouse touchpad".

    Is there any way i can get examine behaving more like luke?

    current code:

    var criteria = ExamineManager.Instance

                //create basic filter to start with
                var filter = criteria
                        .Field("tags", "brilliant mouse touchpad")

                //execute query using custom distinct constraint
                IEnumerable<SearchResult> Results = new List<SearchResult>();
                Results =
                    ExamineManager.Instance.SearchProviderCollection["TestSearcher"].Search(filter.Compile()).Distinct(new SearchResultComparer());


    any insights?




  • Simon Yohannes 58 posts 188 karma points
    Sep 06, 2010 @ 19:27
    Simon Yohannes

    what i don't want to do is have to split the text into words loop through them dynamically adding OR() operators to end up with something equivalent to this:

    var filter = criteria
                        .Field("tags", "touchpad")
                        .Field("tags", "mouse")
                        .Field("tags", "brilliant")

    that would work but is this necessary, or am i missing a particular setting?

    ps: setting default operation of OR in the CreateSearchCriteria factory method won't work in this instance


  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 07, 2010 @ 01:00
    Aaron Powell

    Are you wanting to search for all documents that have those three keywords anywhere, or do you want to search on documents which have those three keywords together? It's different depending on what you're trying to achieve.

    If you're wanting the words together you're not escaping your search, so you end up with a Lucene query like this:

    +tags:touchpad mouse brilliant

    When what you want is:

    +tags:"touchpad mouse brilliant"

    This can be achieved by using the Escape extension method (which resides in UmbracoExamine.SearchCriteria).


    If you're wanting the documents which contain one-or-more of the words you need to do a GroupedOr statement:

    criteria.GroupedOr(new [] { "tags", "tags", "tags" }, "touchpad", "mouse", "brilliant")
    //produces: +(tags:touchpad tags:mouse tags:brilliant)

    Luke can operate differently when searching as it is capable of doing a 'default field' for the search. Examine does not have this feature and this is why 'tag:... ... ...' may be different in Luke to Examine.
    Also, if you're using a different analyzer in Luke (Whitespace is it's default IIRC) to Examine (it's default is StandardAnalyzer) you can receive different results.

  • Simon Yohannes 58 posts 188 karma points
    Sep 07, 2010 @ 11:50
    Simon Yohannes

    thanks for that slace.

    I guess the problem in my case is that the search query is automatically being escaped without me explicitly using the extension method. to achieve the "contains" result i'm after, i will need to resort to dynamically OR'ing words from the query against the fields.



  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 07, 2010 @ 13:52
    Aaron Powell

    The example code you posted wont escape, it'll generate this:

    +(+tags:touchpad mouse brilliant) +__IndexType:content

    The easiest way to do n-level grouped or statements is like this:

    var terms = "touchpad mouse brilliant".Split(" ");
    var fields = Enumerable.Range(0, terms.Length).Select(x => "tags");
    var criteria = searcher.CreateSearchCriteria(IndexType.Content);
    var results = searcher.Search(criteria.GroupedOr(fields, terms).Compile());

    (That's notepad code so it might not be 100% :P)

  • Simon Yohannes 58 posts 188 karma points
    Sep 07, 2010 @ 15:00
    Simon Yohannes

    i don't know what the reason was slace, but it wasn't returning results unless i OR'd every word together ;'/

    now i'm using your neater grouped OR linq goodness which still gives the results i was expecting :]

    thanks again

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 08, 2010 @ 00:44
    Aaron Powell

    If you ever need to find out the lucene query you can just ToString the search criteria object and it's in there :P

Please Sign in or register to post replies

Write your reply to: