Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

How to query for all occurences of <br />?

Avatar

Level 8

Hi,

I need to query for all occurrences of <br />, <br/>, or <br /> in my text components, but my search is not returning any results.

Here is the query I am using:

SELECT * FROM [nt:base] AS n
WHERE n.[sling:resourceType]='xxx/components/content/text'
AND CONTAINS(n.text, '&lt;br')
AND ISDESCENDANTNODE([/content])

However, when I search like this:

SELECT * FROM [nt:base] AS n
WHERE n.[sling:resourceType]='xxx/components/content/text'
AND CONTAINS(n.text, 'br')
AND ISDESCENDANTNODE([/content])

I do get results.

Could you please help me figure out why the first query is not working and how I can correctly search for <br />, <br/>, or <br />? Between br and / there can be one or more space.

Thank you!

1 Accepted Solution

Avatar

Correct answer by
Level 4

Actually CONTAINS function in JCR queries is full-text search based, and it doesn't match HTML tags or special characters like <, > directly. These characters are often ignored by the index during query parsing.

View solution in original post

3 Replies

Avatar

Level 4

Hi @anasustic ,

The original query was searching for the encoded version of <br /> (&lt;br), but the actual text in the text property contains the raw <br /> tag. Therefore, the query didn't return any results because it was looking for the wrong version of the tag.

 

Since the second query works by searching for br, you can simply retrieve the results and then use a regex in Java to process the text and find all occurrences of the <br /> tag.

Feel free to correct me if I’m wrong or share any additional insight.
Thanks.

Avatar

Level 8

 

SELECT * FROM [nt:base] AS n
WHERE n.[sling:resourceType]='xxx/components/content/text'
AND CONTAINS(n.text, '<br />')
AND ISDESCENDANTNODE([/content])

The query is expected to return results where the text property contains the exact match <br />. However, it consistently returns no results, even though I have verified that <br /> exists in the content.

Avatar

Correct answer by
Level 4

Actually CONTAINS function in JCR queries is full-text search based, and it doesn't match HTML tags or special characters like <, > directly. These characters are often ignored by the index during query parsing.