Query throws error using querybuilder but runs fine in querydebug | Community
Skip to main content
Level 4
March 2, 2016
Solved

Query throws error using querybuilder but runs fine in querydebug

  • March 2, 2016
  • 3 replies
  • 1267 views

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.

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 Lokesh_Shivalingaiah

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

3 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
March 3, 2016

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

Level 4
March 3, 2016

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.

smacdonald2008
Level 10
March 3, 2016

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