Every AEM developer knows that a JCR node consists of properties and values. Whenever a component is configured or whenever page properties are set, the value is saved in the JCR node as properties and values.
There are times when we would like to search all the JCR node properties, to match the value with some kind of string. We can do this with fulltext search in AEM. This action is most useful when trying to find unused components in the code.
When performing a fulltext search, please be aware that you will be using Jackrabbit Oak, Apache Lucene. You will search via the Apache Lucene indexes, cached in the JCR. Update and Delete operations in the repository are followed by the Lucene reindexing.
In this article, we will cover 2 ways of performing a full-text search, with examples.
1. AEM FullText Search with the Query Builder
Example 1: In this example we will find all [nt:base] JCR nodes matching any %pants%
1 2 3 4 5 6 7 8 9 10 11 12 | Search for: anything under "/content/we-retail" and any.properties with values LIKE "%pants%" and show me more than 10 results. ------------- http://localhost:4502/libs/cq/search/content/querydebug.html path=/content/we-retail fulltext=pants p.limit=-1 |
Visit localhost: http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&query=path%3D%2Fcontent%2Fwe-retail%0D%0Afulltext%3Dpants%0D%0Ap.limit%3D-1
Example 2: In this example we will find all [cq:Page] JCR nodes matching any %weretail/components/structure/page%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Search for: anything under "/content/we-retail" and only "cq:Page" nodes and any.properties with values LIKE "%weretail/components/structure/page%" and show me more than 10 results. ------------- http://localhost:4502/libs/cq/search/content/querydebug.html path=/content/we-retail type=cq:Page fulltext=weretail/components/structure/page p.limit=-1 |
2. AEM FullText Search with the JCR_SQL2
Step 1. Visit CRX/DE, from the CRX/DE main navigation, Tools > Query.
Step 2. From the Query Console, change the path to JCR_SQL2.
Step 3. Insert your JCR_SQL2 query, and click on Execute. The results should be shown.
Example 1: In this example we will find all [nt:base] JCR nodes matching any %pants%
1 2 3 4 5 6 7 8 9 10 11 12 | Search for: anything under "/content/we-retail" and any.properties with values LIKE "%pants%" and show me more than 10 results. ------------- http://localhost:4502/crx/de/index.jsp SELECT * FROM [nt:base] AS nodes WHERE ISDESCENDANTNODE ([/content/we-retail]) AND CONTAINS(nodes .*, 'pants') |
Visit localhost: http://localhost:4502/crx/de/index.jsp
Example 2: In this example we will find all [cq:Page] JCR nodes matching any %weretail/components/structure/page%
1 2 3 4 5 6 7 8 9 10 11 12 13 | Search for: anything under "/content/we-retail" and only "cq:Page" nodes and any.properties with values LIKE "%weretail/components/structure/page%" and show me more than 10 results. ------------- http://localhost:4502/libs/cq/search/content/querydebug.html SELECT * FROM [cq:Page] AS nodes WHERE ISDESCENDANTNODE ([/content/we-retail]) AND CONTAINS(nodes .*, 'weretail/components/structure/page') |
Visit localhost: http://localhost:4502/crx/de/index.jsp
Just like that! works like magic. thanks sir.
How to search for exact match above examples give any word match from the given word but what if I need exact match
SELECT * FROM [myNodeType] WHERE [title] = ‘Hello World’