AEM Query Question: Find pages with string pattern; print the pages and the match | Community
Skip to main content
this-that-the-otter
Level 4
September 18, 2023

AEM Query Question: Find pages with string pattern; print the pages and the match

  • September 18, 2023
  • 2 replies
  • 2333 views

I can find pages that contain a string pattern:

 

type=cq:Page fulltext=*tion group.1_path=/content/site/en orderby.sort=desc p.limit=10

This seems to print the pages that have the pattern *tion within:

{ "path": "/content/site/foo", "excerpt": "some text here", "name": "page name", "title": "page title", "lastModified": "timestamp", "created": "timestamp" },

 

I want a result that also include the matches themselves, either individually or as multi-values like this:

 

{ "path": "/content/site/foo", "match0": "https://contruction.com", "match1": "tionesta", "match2": "bastion", "excerpt": "some text here", "name": "page name", "title": "page title", "lastModified": "timestamp", "created": "timestamp" },

or:

{ "path": "/content/site/foo", "match0": "https://contruction.com, tionesta, bastion", "excerpt": "some text here", "name": "page name", "title": "page title", "lastModified": "timestamp", "created": "timestamp" },

 Thanks for any info!

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

2 replies

this-that-the-otter
Level 4
September 18, 2023

Hi @santhosh_kumark, Thanks for the reply. I have seen the helpful page you linked to. Is the snippet you posted something that will print the string match(es) and the page path they occur in?

Is there a word for what I want, like "facet" or something like that? Perhaps I can search better (or ask a better question) if I know the term that means: also print the match.

I see the sample code iterates over a resultset but can't tell if it prints the matched strings as well as the page paths. If it does, what part of the code is responsible for printing the page paths and string match(es)?

It looks like the example you suggest is Java. I was hoping for a query using querybuilder syntax. If it's not possible to do using querybuilder syntax, how would I go about using the snippet? Can I put it in a JSP page using crxde? Do I need to import any additional classes, etc.?

Thanks again!

santhosh_kumark
Level 6
September 18, 2023

Hi @this-that-the-otter you can use the below predicates. yes it will give the matching result along with its path.
path=/content
type=cq:Page
group.p.or=true
group.1_fulltext=https://contruction.com
group.1_fulltext.relPath=jcr:content
group.2_fulltext=tionesta
group.2_fulltext.relPath=jcr:content
group.3_fulltext=bastion
group.3_fulltext.relPath=jcr:content
p.offset=0
p.limit=20

http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&isURL=on&query=path%3D%2Fcontent%26type%3Dcq%3APage%26group.p.or%3Dtrue%26group.1_fulltext%3Dhttps%3A%2F%2Fcontruction.com%26group.1_fulltext.relPath%3Djcr%3Acontent%26group.2_fulltext%3Dtionesta%26group.2_fulltext.relPath%3Djcr%3Acontent%26group.3_fulltext%3Dbastion%26group.3_fulltext.relPath%3Djcr%3Acontent%26p.offset%3D0%26p.limit%3D20

 

kautuk_sahni
Community Manager
Community Manager
September 21, 2023

@this-that-the-otter Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni
this-that-the-otter
Level 4
September 21, 2023

Hi @kautuk_sahni, I have replied to @aanchal-sikka.

It would be great if there were encouragement/requirement for answers to be:

- explained

- provide working example

- demonstrate example working (i.e. show the result against sample data using explained and working example)

e.g. like stackoverflow, etc.