Nested Logic in QueryBuilder | Community
Skip to main content
New Participant
April 11, 2023
Solved

Nested Logic in QueryBuilder

  • April 11, 2023
  • 2 replies
  • 1405 views

I am trying to modify querybuilder code to nest some conditions.

The section of my querybuilder code is as follows:

fulltext=searchterm
group.0_path=/content/path1
group.0_path.self=true
group.1_path=/content/path2
group.1_path.self=true
group.p.or=true
orderby=@jcr:score
orderby.sort=desc
property=jcr:content/excludeFromSearch
property.operation=not
2_property=jcr:content/cq:redirectTarget
2_property.operation=not
type=cq:Page
p.limit=-1

Resulting XPath is:
//element(*, cq:Page)
[
(jcr:contains(., 'searchterm')
and not(jcr:content/@excludeFromSearch)
and not(jcr:content/@5644378:redirectTarget))
]
order by @6655266:score descending

I would like to add a 3rd property that can be grouped with the second, so the logic is
not(jcr:content/@excludeFromSearch)

and

(not(jcr:content/@cq:redirectTarget) or (jcr::content/@NEWPROPERTY))

The new property, if it exists, will negate the cq:redirectTarget property. Any help is appreciated.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nitin_laad

Hi @hn_doug To achieve the desired nested conditions in the query, you can add a new group to the existing query with the required properties. The modified code for the querybuilder should look something like this:

fulltext=searchterm group.0_path=/content/path1 group.0_path.self=true group.1_path=/content/path2 group.1_path.self=true group.2_property=jcr:content/@NEWPROPERTY group.2_property.operation=exists group.2_property.value=true group.2_property.1_property=jcr:content/@cq:redirectTarget group.2_property.1_property.operation=not group.2_property.p.or=true group.p.or=true orderby=@jcr:score orderby.sort=desc property=jcr:content/excludeFromSearch property.operation=not 2_property=jcr:content/cq:redirectTarget 2_property.operation=not type=cq:Page p.limit=-1

 

2 replies

ShaileshBassi
New Participant
April 12, 2023

Hi @hn_doug As mentioned in your query above, there is a requirement to create 2 groups.

 

There is an option to include multiple groups while creating the queries.

 

Example:

Group Usage 1:

fulltext=Management group.p.or=true group.1_path=/content/geometrixx/en group.2_path=/content/dam/geometrixx

Group Usage 2:

fulltext=Management group.p.or=true group.1_group.path=/content/geometrixx/en group.1_group.type=cq:Page group.2_group.path=/content/dam/geometrixx group.2_group.type=dam:Asset

So as mentioned in the above sample (Group Usage 2) we have 1_group, 2_group. These are the multiple groups created. IMO, the second example should fix your problem.

 

Hope this helps!

Thanks 

Nitin_laad
Nitin_laadAccepted solution
New Participant
April 12, 2023

Hi @hn_doug To achieve the desired nested conditions in the query, you can add a new group to the existing query with the required properties. The modified code for the querybuilder should look something like this:

fulltext=searchterm group.0_path=/content/path1 group.0_path.self=true group.1_path=/content/path2 group.1_path.self=true group.2_property=jcr:content/@NEWPROPERTY group.2_property.operation=exists group.2_property.value=true group.2_property.1_property=jcr:content/@cq:redirectTarget group.2_property.1_property.operation=not group.2_property.p.or=true group.p.or=true orderby=@jcr:score orderby.sort=desc property=jcr:content/excludeFromSearch property.operation=not 2_property=jcr:content/cq:redirectTarget 2_property.operation=not type=cq:Page p.limit=-1