Copied to clipboard

Flag this post as spam?

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


  • Rob Stevenson-Leggett 38 posts 110 karma points
    Dec 31, 2014 @ 14:37
    Rob Stevenson-Leggett
    0

    Unable to get Examine to filter by multiple doc types

    Hi

    I want to search two of my doc types that exist in the ExternalSearch index.

    I'm getting back results for all doctypes.

    Here's my query:

     ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
     // TODO : This bit of the query doesn't work - returns all node types
     var query = searchCriteria.NodeTypeAlias("Product").Or().NodeTypeAlias("Service");
    
     query = query.And().GroupedOr(new[] {"title", "description"}, new[] { term });
     searchCriteria = query.Compile();
    
     var relatedProducts = Umbraco.ContentQuery.TypedSearch(searchCriteria).Take(count).ToList();
    

    Can anyone see what is wrong? I've tried all sorts of combinations with no luck. I only seem to be able to search 1 or all.

    Any ideas?

  • Alain 73 posts 520 karma points c-trib
    Dec 31, 2014 @ 14:52
  • Doron Uziel 23 posts 93 karma points
    Dec 31, 2014 @ 15:11
    Doron Uziel
    0

    Hi,

    I think that the problem is with this line:

     var query = searchCriteria.NodeTypeAlias("Product").Or().NodeTypeAlias("Service");
    

    I would suggest replacing it with:

     var query = searchCriteria.GroupedOr(new string[] {"__NodeTypeAlias"}, "Product", "Service");
    

    Let me know if this worked out for you. Doron

  • Rob Stevenson-Leggett 38 posts 110 karma points
    Dec 31, 2014 @ 16:46
    Rob Stevenson-Leggett
    0

    Thanks for the responses, I also had to change the default operation to BooleanOperation.And as otherwise the generated query looked like this:

    (nodeTypeAlias:product nodeTypeAlias:service) +(title:test description:test)
    

    and still returned other doc types.

Please Sign in or register to post replies

Write your reply to:

Draft