Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

GraphQL Tag search using CONTAINS_NOT

Avatar

Level 2

Hi folks,

 

I have a (simplified) query for searching Content Fragments where sometimes I want to exclude certain tags:

 

query getHelpFaqSearch(
$value1: String!,
$operator1: StringOperator = CONTAINS) {
helpFaqList (
filter: {
_tags: {
_logOp: AND
_expressions: [
{
value: $value1,
_operator: $operator1
}
]
}
}
) {
items {
question
answer {
html
}
lastUpdated
tags
_path
}
}
}

However; if I use the VARs:
{
     "value1": "domain:digital/booking/make",
     "operator1": "CONTAINS_NOT"
}

 

I get back results like:

 

...

"tags": [
    "domain:digital/booking/make",
    "domain:digital/booking/connections",
    "domain:digital/travel/day-of-travel",
    "domain:digital/travel/get-ready-to-travel"
],

...

 

This entry doesn't return:

...

"tags": [
    "domain:digital/booking/make"
],
...

 

If on the second example I add another tag then that results returns also. So the result is getting hit because of the new tag.

 

Is there anyway of excluding a CF if a tag exists in both cases?

 

Thanks,

Graham

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

If I understood your requirement correctly then I guess your query is not working with CONTAINS_NOT when the content fragment has more than 1 tags attached to it. You can try using _apply attribute maybe like below and check if you get desired results. 

_expressions: [ 
                    {
                        value: $value1,
                        _operator: $operator1,
                        _apply:ALL
                    }
                ]




View solution in original post

5 Replies

Avatar

Community Advisor

Hi @chebwin ,

Can you try to do it with filter attribute. 
I have provided the sample code:

 filter: {tags: {elemMatch: {slug: {eq: "haka"}}}},

 

 

-Tarun

Avatar

Correct answer by
Community Advisor

If I understood your requirement correctly then I guess your query is not working with CONTAINS_NOT when the content fragment has more than 1 tags attached to it. You can try using _apply attribute maybe like below and check if you get desired results. 

_expressions: [ 
                    {
                        value: $value1,
                        _operator: $operator1,
                        _apply:ALL
                    }
                ]




Avatar

Level 2

This looks promising; of course I have another high profile bug to test first but will update this ticket later this week.

Avatar

Level 2

Apologies project work pulled me away. I had to modify it a bit so that you match AT_LEAST_ONCE for CONTAINS and ALL for CONTAINS_NOT:

query getHelpFaqSearch(
  $value1: String!,
  $operator1: StringOperator = CONTAINS,
  $apply1: ArrayMode = AT_LEAST_ONCE,
  $value2: String = "",
  $operator2: StringOperator = CONTAINS,
  $apply2: ArrayMode =  AT_LEAST_ONCE) {
  helpFaqList (
    filter: {
      tags: {
        _logOp: AND
        _expressions: [ 
          {
            value: $value1,
            _operator: $operator1,
            _apply: $apply1
          },
          {
            value: $value2,
            _operator: $operator2,
            _apply: $apply2
          }
        ]
      }
    }
  ) {
    items {
      question
      answer {
        html
      }
      lastUpdated
      tags
      _path
    }
  }
}

VARS
{
  "value1": "domain:digital/contact-us/ba",
  "operator1": "CONTAINS",
  "value2": "domain:digital/booking/voluntary-change",
  "operator2": "CONTAINS_NOT",
  "apply2": "ALL" 
}

Avatar

Administrator

@chebwin Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni