Expand my Community achievements bar.

JCR:Query Search with special character

Avatar

Level 2

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}
]

8 Replies

Avatar

Community Advisor

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 ?

Avatar

Community Advisor

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...

Its working fine i am able get the result.

Avatar

Level 2

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.

Avatar

Level 2

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

Avatar

Community Advisor

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

Avatar

Level 10

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')

Avatar

Level 2

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

Avatar

Level 10

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.