Copied to clipboard

Flag this post as spam?

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


  • Tom van Enckevort 107 posts 429 karma points
    May 30, 2017 @ 13:42
    Tom van Enckevort
    0

    Examine normal query doesn't work, but raw query does...

    So I'm doing something that looks to me as quite straightforward; finding a bunch of nodes that live under a specific root node:

    var searcher = ExamineManager.Instance.SearchProviderCollection[Constants.Examine.InternalSearcher];
    ISearchCriteria searchCriteria = searcher.CreateSearchCriteria();
    
    // limit to defined root node ID
    var filter = searchCriteria.Field("__Path", @"\-1," + rootNodeId.ToString().MultipleCharacterWildcard().Value);
    
    // only search events
    filter = filter.And().GroupedOr(new[] { "nodeTypeAlias" }, "myEvent");
    
    var query = filter.Compile();
    
    // search
    var results = searcher.Search(query);
    

    The above code gives me no results, even though there are nodes available.

    However when I change the last two lines to this:

    var query = filter.Compile() as LuceneSearchCriteria;
    
    // create new query using the raw Lucene query string
    var query2 = searcher.CreateSearchCriteria().RawQuery(query.Query.ToString());
    
    // search
    var results = searcher.Search(query2);
    

    And it now does return the correct results...

    Does anyone know why that would be the case?

  • Adam 8 posts 86 karma points
    Jun 27, 2019 @ 14:40
    Adam
    1

    Normally when you have that situation, means that something is wrong with your query. In your case try to replace:

    var filter = searchCriteria.Field("__Path", @"\-1," + rootNodeId.ToString().MultipleCharacterWildcard().Value);
    filter = filter.And().GroupedOr(new[] { "nodeTypeAlias" }, "myEvent");
    

    to

    var filter = searchCriteria.Field("__Path", ("-1," + rootNodeId.ToString() + ",").MultipleCharacterWildcard())
    .And().Field("nodeTypeAlias", "myEvent");
    

    And it should work ;-)

  • Tom van Enckevort 107 posts 429 karma points
    Jun 27, 2019 @ 14:44
    Tom van Enckevort
    1

    Thanks for the reply.

    Unfortunately I'm not able to test this, since it was over two years ago since I worked on this particular project :-)

  • Adam 8 posts 86 karma points
    Jun 27, 2019 @ 19:47
    Adam
    0

    Ahh, no prob, I just placed this comment here in case if any one else will have similar issue :)

  • Mike Chambers 636 posts 1253 karma points c-trib
    Aug 22, 2019 @ 08:24
    Mike Chambers
    0

    Hi Tom, when using the fluent API as you have it, if I look at the resultant lucene query

    string stringToParse = searchCriteria.ToString();
    int indexOfPropertyValue = stringToParse.IndexOf("LuceneQuery:") + 12;
    string rawQuery = stringToParse.Substring(indexOfPropertyValue).TrimEnd('}');
    

    I see

    +__Path:1 +nodeTypeAlias:myEvent
    

    the negative seems to be stripped???

    I'm querying the internalIndexer on an umb 8.1.2 site... Do you know why this is, and any work arounds?

  • Tom van Enckevort 107 posts 429 karma points
    Aug 22, 2019 @ 08:27
    Tom van Enckevort
    0

    Sorry, I haven't used Examine in v8 yet, so I don't know whether things might work differently there compared to v7.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies