Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Query throws error using querybuilder but runs fine in querydebug

Avatar

Level 5

Here is the query, it runs fine in querybuilder returning zero records that match, which is OK.

path=/content/imf/en/board-meetings/calendar
type=cq:EventCalendar
fulltext= Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF - An IEO Evaluation
fulltext.relPath=@jcr:title;
orderby=@boardDate
orderby.sort=desc;
p.limit=0

 

But if I run the same using the code,

Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("path", BOARD_MEETING_EVENTS_PATH);
        paramMap.put("type", "cq:EventCalendar");
        paramMap.put("fulltext", documentInfo.getDocumentTitle());
        paramMap.put("fulltext.relPath", "@jcr:title");
        paramMap.put("orderby", "@boardDate");
        paramMap.put("orderby.sort", "desc");
        paramMap.put("p.limit", "0");

        Query query = queryBuilder.createQuery(PredicateGroup.create(paramMap),
                session);

        SearchResult searchResult = query.getResult();

 

Throws error:

 

/jcr:root/content/imf/en/board-meetings/calendar//*[jcr:contains(@jcr:title;(*), 'Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF - An IEO Evaluation')] order by @boardDate descending; expected: ,

javax.jcr.query.InvalidQueryException: java.lang.IllegalArgumentException: Invalid expression: 'Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF - An IEO Evaluation'

               at org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl.executeQuery(QueryManagerImpl.java:142)

               at org.apache.jackrabbit.oak.jcr.query.QueryImpl$2.perform(QueryImpl.java:101)

               at org.apache.jackrabbit.oak.jcr.query.QueryImpl$2.perform(QueryImpl.java:98)

               at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:216)

               at org.apache.jackrabbit.oak.jcr.query.QueryImpl.execute(QueryImpl.java:97)

               at com.day.cq.search.impl.builder.QueryImpl.executeXpath(QueryImpl.java:391)

               at com.day.cq.search.impl.builder.QueryImpl.execute(QueryImpl.java:429)

               at com.day.cq.search.impl.builder.QueryImpl.getResult(QueryImpl.java:106)

               at org.imf.document.service.impl.DocumentServiceImpl.findDocumentRelatedEvents(DocumentServiceImpl.java:1024)

               at org.imf.document.service.impl.DocumentServiceImpl.publishDocument(DocumentServiceImpl.java:343)

 

If I change the title of the document to not have any "-", it works fine. How can we overcome this because titles are going to have a "-" in them.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

path=/content/imf/en/board-meetings/calendar
type=cq:EventCalendar
fulltext= Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF - An IEO Evaluation
fulltext.relPath=@jcr:title;
orderby=@boardDate
orderby.sort=desc;
p.limit=0

I tried with '-' in the query builder and in the query builder, I got the 'IllegalargumentException'

but when I tried with the escape character '/' , it worked fine. Can you try this and see if it works for you aswell ?

ex: add the escape character if your searchtext has '-' in it.

path=/content/imf/en/board-meetings/calendar
type=cq:EventCalendar
fulltext= Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF /- An IEO Evaluation
fulltext.relPath=@jcr:title;
orderby=@boardDate
orderby.sort=desc;
p.limit=0

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

path=/content/imf/en/board-meetings/calendar
type=cq:EventCalendar
fulltext= Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF - An IEO Evaluation
fulltext.relPath=@jcr:title;
orderby=@boardDate
orderby.sort=desc;
p.limit=0

I tried with '-' in the query builder and in the query builder, I got the 'IllegalargumentException'

but when I tried with the escape character '/' , it worked fine. Can you try this and see if it works for you aswell ?

ex: add the escape character if your searchtext has '-' in it.

path=/content/imf/en/board-meetings/calendar
type=cq:EventCalendar
fulltext= Statement by the Managing Director on the IEO Report on Behind the Scenes with Data at the IMF /- An IEO Evaluation
fulltext.relPath=@jcr:title;
orderby=@boardDate
orderby.sort=desc;
p.limit=0

Avatar

Level 5

Great tip. Thanks. That worked. It's just surprising since text can always have hyphens.

Didn't know though that you could escape it that way. For now we will use that fix, but hoping product can handle hyphen in future.

Avatar

Level 10

Excellent info, we will update help community article. Good work Lokesh