Copied to clipboard

Flag this post as spam?

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


  • steschu 88 posts 489 karma points
    Jul 15, 2020 @ 09:13
    steschu
    0

    How does "GroupedNot" work in Examine?

    Hello,

    Can anybody help me with the GroupedNot Method of the SearchCriteria in Examine? So far I presumed that GroupedNot has the opposite effect of GroupedAnd. But in my example code, GroupedNot always has 0 matches no matter what I am searching.

    ISearchCriteria searchCriteria = ExamineManager.Instance.CreateSearchCriteria();
    
    // {+(+umbracoNavihide:0)}, those pages found that are hidden from navigation
    queryNodes = searchCriteria.GroupedAnd(new string[] { "umbracoNavihide" }, "0");
    
    // {(-umbracoNavihide:1)}, 0 matches found
    queryNodes = searchCriteria.GroupedNot(new string[] { "umbracoNavihide" }, "1");
    
    // {(-umbracoNavihide:0)}, 0 matches found
    queryNodes = searchCriteria.GroupedNot(new string[] { "umbracoNavihide" }, "0");
    

    Version Used: 7.15.3

    Cheers, Stephan

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 18, 2020 @ 08:34
    Marc Goodson
    100

    Hi Stephan

    Examine is a wrapper around Lucene - and I think therefore the GroupedNot option in Examine, relates to Lucene's NOT functionality.

    https://lucene.apache.org/core/294/queryparsersyntax.html#NOT

    With Examine often a good way to explore how things, work is to look in the Unit Tests of the Examine project:

    https://github.com/Shazwazza/Examine/blob/82c44fd84c5eb17032e7736408f233339d035ff9/src/Examine.Test/Search/FluentApiTests.cs#L461

    Anyway the gist I get, the GroupedNot is to provide a list of fields and corresponding list of values for those fields that will exclude the search result if it includes that combination.... but I think it cannot be just used as a NOT, you have to initially establish something you are searching for, and then Lucene can search for 'x' but NOT 'y', it can't search for just NOT 'y' ... but I may be misunderstanding, and you might have more in your example than 'just the NOT'. If you look in the Examine tests for GroupNot above, you can see the code searches FOR a particular doc type, but combined with NOT a certain list of ids....

    I have a feeling if you just want to filter by documents that aren't hidden from navigation then, your GroupedAnd is the way to go... eg:

    queryNodes = searchCriteria.GroupedAnd(new string[] { "umbracoNavihide" }, "1");
    

    So yo may not need NOT at all, but if you need to use NOT then I think you need to search for something else 'first' to combine with the NOT.

    regards

    Marc

  • steschu 88 posts 489 karma points
    Jul 23, 2020 @ 14:07
    steschu
    0

    Hi Marc,

    Thanks for your reply and explanation. When the NOT must be combined with a preceeding statement I will try to put it at the end. I always startet with the NOT so far.

    I did not use the GroupedAnd because I also want to search media files which have no property umbracoNavihide ("return everything except Documents that are hidden).

    Kind regards, Stephan

Please Sign in or register to post replies

Write your reply to:

Draft