Copied to clipboard

Flag this post as spam?

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

  • Nik 1304 posts 5550 karma points MVP 3x c-trib
    Jun 11, 2019 @ 10:01

    Examine - Search where A or (B and C) - Nested Queries


    I'm attempting to perform a search in v8's version of Examine using the fluent api. However, I'm trying to add filtering to my search to reduce down the number of unrequired results. To do this I want to search as follows:

    1. Where (ItemType = Content) or (ItemType = Media and File Extension = PDF)
    2. Where search term is found

    To do this I'm doing the following:

     var query = searcher.CreateQuery().Group((e) => 
             e.Field("__IndexType" , "content").Or()
               .GroupedAnd(new List<string> { "__IndexType", "umbracoExtension" }, new string[] { "media", "pdf" }))

    In theory, this looks correct but the start of my actual lucene query ends up looking like this:

    (+__IndexType:content (+__IndexType:media +umbracoExtension:pdf))

    And as a result this returns 0 results which is not what I'm expecting.

    If I use LUKE to query the index directly and I remove the first + from highlighted part of the query then I get the results I'm expecting. Any one got ideas on how I can get my nested query to generate without the first + ?



  • Ismail Mayat 4503 posts 10046 karma points MVP 2x admin c-trib
    Jun 11, 2019 @ 10:05
    Ismail Mayat

    So in v7 or older examine you would let the boolean operation to OR rather than and. So you could try something similar not sure how though.

    Or worse case just use raw query, so:

    (__IndexType:content (+__IndexType:media +umbracoExtension:pdf))



  • Nik 1304 posts 5550 karma points MVP 3x c-trib
    Jun 11, 2019 @ 10:53

    So in V8, you can do it at the very start of the creation of a query, you can set the default boolean operation, but you don't seem to be able to do that in a nested query. Despite you getting the option to pass you choice in when calling the Group method.

    It's odd, I think I have to go with the raw query approach though even though it's not as nice to read imo.

    Thanks for you help :-) Hadn't thought of trying mixing a raw query with the rest of the fluent api before :-)

Please Sign in or register to post replies

Write your reply to: