How to query for all occurences of <br />? | Community
Skip to main content
Level 6
April 29, 2025
Solved

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

  • April 29, 2025
  • 1 reply
  • 474 views

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.
Best answer by ShivamKumar

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.

1 reply

Level 4
April 29, 2025

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.

anasusticAuthor
Level 6
April 29, 2025

 

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.

ShivamKumarAccepted solution
Level 4
April 29, 2025

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.