Skip to main content
Level 6
Apr 29, 2025 8:44 AM UTC
Solved

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

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ShivamKumarAccepted solution
Level 4
Apr 29, 2025 9:50 AM UTC

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.

3 replies

Level 4
Apr 29, 2025 9:38 AM UTC

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.

Translate
anasusticAuthor
Level 6
Apr 29, 2025 9:44 AM UTC

 

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.

Translate
ShivamKumarAccepted solution
Level 4
Apr 29, 2025 9:50 AM UTC

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.

Translate