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

Avatar

Avatar

cqsapientu69896

Avatar

cqsapientu69896

cqsapientu69896

10-11-2020

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

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

11-11-2020

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!

Answers (1)

Answers (1)

Avatar

Avatar

TUmesh

Avatar

TUmesh

TUmesh

11-11-2020

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