Copied to clipboard

Flag this post as spam?

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


  • Lennart Stoop 304 posts 842 karma points
    Feb 01, 2012 @ 15:38
    Lennart Stoop
    0

    Examine fluent API: grouping boolean operations

    Hi all,

    I'm trying to tweak an Examine search query and for this I'm using the fluent API. I'm close to a solution but there is just one thing I can't get my head around.

    I'm using the code below to split the user's search query into seperate terms and since I have multiple indexed fields I'm using the GroupedOr method to create the search criteria.

                var searchTerms = searchQuery.Split(' ');
                foreach (string term in searchTerms)
                {
                    if (!String.IsNullOrEmpty(term))
                    {
                        if (termQueries == null)
                            termQueries = searcher.CreateSearchCriteria()
                                .GroupedOr(searchFields, term.Escape().Value.MultipleCharacterWildcard());
                        else
                            termQueries = termQueries.Or()
                                .GroupedOr(searchFields, term.Escape().Value.MultipleCharacterWildcard());
                    }
                }

    This would result in the following Lucene query:

    +(bodyText:hello* message:hello*) (bodyText:world* message:world*) ...

    As you can see the first group is required (+) and the second group is optional (or). The query I'm trying to create however should leave both groups optional, but at least 1 group is required, like so:

    +((bodyText:hello* message:hello*) (bodyText:world* message:world*)) ...

     

    Any ideas how this can be accomplished using the fluent API?

     

    Grtz

    L

  • Lennart Stoop 304 posts 842 karma points
    Feb 08, 2012 @ 12:55
    Lennart Stoop
    0

    Suggestions, anyone? *bump* :-)

  • Sune Jepsen 25 posts 109 karma points
    Feb 08, 2012 @ 12:57
    Sune Jepsen
    0

    Hey Lennart

    I dont know if this ressource could help you out with you issue. http://our.umbraco.org/forum/developers/extending-umbraco/19329-Search-multiple-fields-for-multiple-terms-with-examine

     

    /Sune

  • Lennart Stoop 304 posts 842 karma points
    Feb 08, 2012 @ 13:30
    Lennart Stoop
    0

    Hi Sune, 

    The thread discusses the grouping of terms/fields, but does not contain any info on how those groups can be grouped together.

    I'm not even sure if that can be done with the fluent API, but I would prefer not having to assemble the Lucene query myself.

    Perhaps there's a totally different approach to what I'm trying to achieve... Just haven't found one yet :-)

    Thanks for the pointer though

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    May 16, 2016 @ 15:18
    Ismail Mayat
    0

    Lennard,

    When you create your search criteria do u passed on Boolean.Or becuase the default is Boolean.And

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft