Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

QueryBuilder returning 0 results

Avatar

Level 3

I have a servlet extended from SlingAllMethodsServlet that is using QueryBuilder to search for images in a path in our repository. When I execute the servlet, QueryBuilder returns 0 results, but when I run the same query from the querydebug.html provided by CQ it returns the expected results.

I've set the log level for com.day.cq.search to DEBUG in an attempt to find my error but I'm seeing the same output in the logger for both query attempts (except that the servlet request returns 0 results). Here is the log output from the servlet call:

18.12.2014 11:49:49.130 *INFO* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] cq5.mil.navy.history.util.impl.filters.LoggingFilter request for /libs/cq/search/content/createAssetPages, with selector null
18.12.2014 11:49:49.132 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl executing query (URL):
path=%2fcontent%2fdam%2fnhhc%2four-collections%2fphotography&property=jcr%3acontent%2fmetadata%2fdam%3aPhysicalheightindpi&property.value=96&type=dam%3aAsset
18.12.2014 11:49:49.133 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl executing query (predicate tree):
ROOT=group: [
    {path=path: path=/content/dam/nhhc/our-collections/photography}
    {property=property: value=96, property=jcr:content/metadata/dam:Physicalheightindpi}
    {type=type: type=dam:Asset}
]
18.12.2014 11:49:49.133 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query: /jcr:root/content/dam/nhhc/our-collections/photography//element(*, dam:Asset)[jcr:content/metadata/@dam:Physicalheightindpi = '96']
18.12.2014 11:49:49.155 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query took 22 ms
18.12.2014 11:49:49.164 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl >> xpath query returned 0 results (counted)
18.12.2014 11:49:49.165 *DEBUG* [0:0:0:0:0:0:0:1 [1418921389129] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl entire query execution took 32 ms

And here is the output from querydebug.html:

18.12.2014 11:49:56.611 *INFO* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] cq5.mil.navy.history.util.impl.filters.LoggingFilter request for /libs/cq/search/content/querydebug, with selector null
18.12.2014 11:49:56.614 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl executing query (URL):
path=%2fcontent%2fdam%2fnhhc%2four-collections%2fphotography&property=jcr%3acontent%2fmetadata%2fdam%3aPhysicalheightindpi&property.value=96&type=dam%3aAsset
18.12.2014 11:49:56.614 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl executing query (predicate tree):
ROOT=group: [
    {path=path: path=/content/dam/nhhc/our-collections/photography}
    {property=property: value=96, property=jcr:content/metadata/dam:Physicalheightindpi}
    {type=type: type=dam:Asset}
]
18.12.2014 11:49:56.615 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query: /jcr:root/content/dam/nhhc/our-collections/photography//element(*, dam:Asset)[jcr:content/metadata/@dam:Physicalheightindpi = '96']
18.12.2014 11:49:56.623 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query took 9 ms
18.12.2014 11:49:56.657 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl >> xpath query returned 206 results (counted)
18.12.2014 11:49:56.659 *DEBUG* [0:0:0:0:0:0:0:1 [1418921396611] GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl entire query execution took 45 ms

Here is the code that's running the query in the servlet:

            Map<String,String> parms = new HashMap<String,String>();

            parms.put("type", "dam:Asset" );

            parms.put( "path", "/content/dam/nhhc/our-collections/photography" );

            // This search is only for low-res images so use the DPI value to keep from returning high-res images

            parms.put( "property", "jcr:content/metadata/dam:Physicalheightindpi" );

            parms.put(  "property.value", "96" );

            if( nodeName != null && !nodeName.isEmpty() ) {

                parms.put(  "nodename", nodeName );

            }

            Query query = builder.createQuery( PredicateGroup.create( parms ), session );

As far as I can tell, the queries are identical so I have no clue as to why my servlet query returns no results. Any suggestions on what I may be doing wrong would be greatly appreciated!

1 Accepted Solution

Avatar

Correct answer by
Level 3

It turns out that it was a permissions issue. I had used resolverFactory.getResourceResolver rather than resolverFactory.getAdministrativeResourceResolver. Once I corrected that the problem was solved.

View solution in original post

7 Replies

Avatar

Level 9

Can you please try renaming dam:Physicalheightindpi to some other without :

Or Try querying some other property which doesn't have :

Avatar

Correct answer by
Level 3

It turns out that it was a permissions issue. I had used resolverFactory.getResourceResolver rather than resolverFactory.getAdministrativeResourceResolver. Once I corrected that the problem was solved.

Avatar

Level 10

Hi

What is your returnType from the servlet ?

Avatar

Level 3

I removed all of the predicates except the path and am now seeing an exception thrown:

18.12.2014 13:28:02.414 *DEBUG* [0:0:0:0:0:0:0:1 [1418927282408] GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query: /jcr:root/content/dam/nhhc/our-collections/photography//*
18.12.2014 13:28:02.417 *WARN* [0:0:0:0:0:0:0:1 [1418927282408] GET /libs/cq/search/content/createAssetPages HTTP/1.1] org.apache.jackrabbit.core.query.lucene.DescendantSelfAxisQuery Access denied to node id fce46b7e-322e-43bd-9659-baa13eed99a6.

That same query works successfully from querydebug. 

Is there some step I'm missing in deploying the servlet? I built the bundle using Maven, then installed it using http://localhost:4502/system/console/bundles.

Avatar

Level 9

This is interesting, at least it gives some warning.  It seems that DescendantSelfAxisQuery throws this exception when node is not found.

There is on jira issue noted due to this error. I am not sure whether this is the case for you. Please check the following link

https://issues.apache.org/jira/browse/JCR-3412

Avatar

Level 7
JAVA servlet that gets a query builder from the request as follows and runs a request to find a content fragment in the DAM

: blah blah
map
.put("p.limit", "-1");
QueryBuilder queryBuilder = req.getResourceResolver().adaptTo(QueryBuilder.class);
Query query = queryBuilder.createQuery(PredicateGroup.create(map),
req.getResourceResolver().adaptTo(Session.class));
final SearchResult result = query.getResult();

hi folks,

I've a similar sounding problem, using querybuilder debugger directly always give me a hit, but the above code returns 0 hits in several environments.. Since it seems to be environment specific, could it be something to do with the ACL permissions on the DAM content fragment that I am searching for ( which has some text that I read.) ? I am not sure what I should be looking for.

thanks 

Fiona

 

 

Avatar

Level 7

I checked in crx/de on the publisher and indeed my content fragment did not have read permission for anonymous/everyone.