Find AEM JCR Nodes with Full Text Search

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

Visit localhost: http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Afulltext%3Dweretail%2Fcomponents%2Fstructure%2Fpage%0D%0Ap.limit%3D-1


2. AEM FullText Search with the JCR_SQL2

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


Was this post helpful?

Hello, I am an active Adobe Community Advisor & a certified Lead AEM Developer who is currently working as a Senior AEM Full Stack Developer. I have over a decade of overall web engineering experience and many years (more than 6) of AEM experience in practice. I hope to give back to the AEM Full Stack Development community by sharing my knowledge with the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top