JCR:Query Search with special character | Community
Skip to main content
Level 2
March 4, 2016

JCR:Query Search with special character

  • March 4, 2016
  • 3 replies
  • 5474 views

Hi ,

 

I am unable to get search result if i am searching with word with special character but from the crx/de i am getting results.Please insight me here  and how can i search these french words .

search keyword = fulltext=*Vidéos*

 

query>ROOT=group: limit=0[

    {group=group: or=true[
        {1_fulltext=fulltext: relPath=@jcr:content/details/sku, fulltext=*Vidéos*}
        {2_fulltext=fulltext: relPath=@jcr:content/jcr:title, fulltext=*Vidéos*}
    ]}
    {path=path: path=}
    {type=type: type=cq:Page}
    {1_orderby=orderby: sort=dsc, orderby=@jcr:content/cq:lastModified}
]

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Mani_kumar_
Community Advisor
Community Advisor
March 4, 2016

D Patty wrote...

Hi ,

 

I am unable to get search result if i am searching with word with special character but from the crx/de i am getting results.Please insight me here  and how can i search these french words .

search keyword = fulltext=*Vidéos*

 

query>ROOT=group: limit=0[

    {group=group: or=true[
        {1_fulltext=fulltext: relPath=@jcr:content/details/sku, fulltext=*Vidéos*}
        {2_fulltext=fulltext: relPath=@jcr:content/jcr:title, fulltext=*Vidéos*}
    ]}
    {path=path: path=}
    {type=type: type=cq:Page}
    {1_orderby=orderby: sort=dsc, orderby=@jcr:content/cq:lastModified}
]

 

Can you please tell me where your not able to get it from Query builder API ?

Mani_kumar_
Community Advisor
Community Advisor
March 4, 2016

I tried it in querydebugger in AEM

path=/content
type=cq:Page
1_fulltext=*énglish*

 

http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&query=path%3D%2Fcontent%0D%0Atype%3Dcq%3APage%0D%0A1_fulltext%3D*%C3%A9nglish*%0D%0A

Its working fine i am able get the result.

psjaison
Level 2
March 4, 2016

Hi Patty,

 

Iam able to get results using query builder. please find the attached screenshot. Please let me know if you need help in querying any french words.

d_pattyAuthor
Level 2
March 4, 2016

Hi Thanks for you reply.I too can get the result using QueryDebugger client. But my problem is when i am doing it from the code using QueryBuilder Api it is not giving me any result. I had given the generated query from the logs.

 

Thanks,

Patty

Mani_kumar_
Community Advisor
Community Advisor
March 4, 2016

D Patty wrote...

Hi Thanks for you reply.I too can get the result using QueryDebugger client. But my problem is when i am doing it from the code using QueryBuilder Api it is not giving me any result. I had given the generated query from the logs.

 

Thanks,

Patty

 

Hi below is the querybuilder api its working fine and giving me result.

QueryBuilder qb = null;
                String param = null;
                ResourceResolver resourceResolver = req.getResourceResolver();
                Map<String, String> map = new HashMap<String, String>();
                map.put("path",
                        "/content");
                map.put("type", "cq:Page");
                map.put("1_fulltext", "*énglish*");
                qb = resourceResolver.adaptTo(QueryBuilder.class);
                Query query = qb.createQuery(PredicateGroup.create(map), resourceResolver.adaptTo(Session.class));
                SearchResult sr = query.getResult();
                if (sr.getHits().size() > 0) {
                    Log.debug("Found");
                } else {
                    Log.debug("Not Found");
                }

 

Thanks,

Mani Kumar K

Amit_Kumar
Level 10
March 4, 2016

D Patty wrote...

Hi ,

 

I am unable to get search result if i am searching with word with special character but from the crx/de i am getting results.Please insight me here  and how can i search these french words .

search keyword = fulltext=*Vidéos*

 

query>ROOT=group: limit=0[

    {group=group: or=true[
        {1_fulltext=fulltext: relPath=@jcr:content/details/sku, fulltext=*Vidéos*}
        {2_fulltext=fulltext: relPath=@jcr:content/jcr:title, fulltext=*Vidéos*}
    ]}
    {path=path: path=}
    {type=type: type=cq:Page}
    {1_orderby=orderby: sort=dsc, orderby=@jcr:content/cq:lastModified}
]

 

Use

Text.escapeIllegalXpathSearchChars(searchTerm); Read this for details https://jackrabbit.apache.org/api/1.4/org/apache/jackrabbit/util/Text.html

Note: If passing this term from Front End use sling:encode('searchTerm', 'HTML')

d_pattyAuthor
Level 2
March 4, 2016

Thanks for your reply.I tried Text.escapeIllegalXpathSearchChars(searchTerm) but seems it is also not working.

Amit_Kumar
Level 10
March 4, 2016

D Patty wrote...

Thanks for your reply.I tried Text.escapeIllegalXpathSearchChars(searchTerm) but seems it is also not working.

 

Ahh sorry I forgot about 

The list of characters that are not encoded by the escape() and unescape() METHODS. They contains the characters as defined 'unreserved' in section 2.3 of the RFC 2396 'URI generic syntax':
 unreserved  = alphanum | mark
 mark        = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"

Can you try any other special char but these meanwhile I will write a sample code for your * char.