Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Exclude child path from fulltext search parent path using Querybuilder OR get search hit excerpt from XPATH/JCR SQL2 query

Avatar

Level 4

I want to exclude child nodes path from search path using querybuilder 

 

for example - parent folder is /content/mysite/en

 

and subfolders are

 

/content/mysite/en/testfolder1

/content/mysite/en/testfolder2

 

I want query builder to write a query to exclude these paths

 

I already looked at this question - 

https://stackoverflow.com/questions/45292778/aem-query-builder-exclude-a-folder-in-search

but grouping paths and p.not=true doesn't seem to be working as expected

 

I know it's a bit tricky to write such a query using query builder ; so I am using JCR/SQL2 query  - 

 

using 

 

SELECT * FROM [cq:Page] 
WHERE ISDESCENDANTNODE(page,'/content/mysite/en') 
AND CONTAINS(*, 'fulltext') 
AND NOT ISDESCENDANTNODE(page, '/content/mysite/en/testfolder1') 
AND NOT ISDESCENDANTNODE(page, '/content/mysite/en/testfolder2')

 

but the issue now is that We also want the search excerpt which is created automatically by querybuilder api's SearchResult's hit object - 

 

hit.getExcerpt()

 so is there a way I can get the excerpt using JCR/SQL2 query ?

 

OR is there a way I can build the exclude subfolder query using querybuilder; so that I can get excerpts from results? Both solutions will solve my case. 

 

If anyone has experience in excluding subfolder query using querybuilder; or building search excerpt using JCR/SQL2 query; or any other idea/suggestion for this case;  help will be much appreciated

 

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi @cqsapientu69896 

You can pass query map with properties as mentioned below to QueryBuilder API, define paths which needs to be excluded in group as highlighted below & then you can get hit.getExcerpt() from QueryBuilder search result.

 

1_property=property-name
1_property.value=property-value
path=/content/mysite/en
group.1_group.p.not=true
group.1_group.path=/content/mysite/en/testfolder1
group.1_group.path.self=true
group.2_group.p.not=true
group.2_group.path=/content/mysite/en/testfolder2
group.2_group.path.self=true

 

 

Hope this helps!

View solution in original post

2 Replies

Avatar

Community Advisor

can you check with 

 String sql= "SELECT * FROM sling:Folder WHERE jcr:path LIKE '"+path +"/%'  AND NOT jcr:path LIKE '"+path +"/%/%'";

that I got from one of the old community  you can check it on below link.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/question-regarding-query-b...

hope this will help.

Umesh Thakur

Avatar

Correct answer by
Level 8

Hi @cqsapientu69896 

You can pass query map with properties as mentioned below to QueryBuilder API, define paths which needs to be excluded in group as highlighted below & then you can get hit.getExcerpt() from QueryBuilder search result.

 

1_property=property-name
1_property.value=property-value
path=/content/mysite/en
group.1_group.p.not=true
group.1_group.path=/content/mysite/en/testfolder1
group.1_group.path.self=true
group.2_group.p.not=true
group.2_group.path=/content/mysite/en/testfolder2
group.2_group.path.self=true

 

 

Hope this helps!