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!

aanchal-sikka
Community Advisor
Community Advisor
September 19, 2023

Hi @santhosh_kumark I want to search the sub string "tion"  and find matches that contain it.

I want to print the page path and the matched string(s).

For example, searching for "tion" - I want to find any string that contains "tion" and the page on which it occurs. I want to print the string match and the page.

Construction, Tionesta, and Bastion are examples of what my query might find. I do not have these in mind ahead of the query.

If a page contains several strings that contain "tion" or just one, I want to print them or it, along with the page path - for example:

If https://www.adobe.com/about-adobe.html was one of the pages in my results, I want the json record of the result for this page to contain:

path: /about-adobe.html

match: Information, Solutions, education, Relations, applications (or each match on a separate line).

Thanks!


Hello @this-that-the-otter 

 

Please refer to https://github.com/paulrohrbeck/aem-links/blob/master/querybuilder_cheatsheet.md

 

Query would be:

path=/content/wknd/language-masters/en type=cq:Page fulltext=*tion* p.limit=-1 p.facets=true

 

We would need Java code to extract the Facets

Map<String, Facet> facets = result.getFacets();
for (String key : facets.keySet()) {
    Facet facet = facets.get(key);
    if (facet.getContain**bleep**()) {
        for (Bucket bucket : facet.getBuckets()) {
            long count = bucket.getCount();
            Map<String, String> params = bucket.getPredicate().getParameters();
            for (String k : params.keySet()) {
                out.println("<br>k:"+k);
            }
        }
    }
}

 

Aanchal Sikka
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.