Servlets 从servlet中调用时,CQ5 QueryBuilder不返回任何结果

Servlets 从servlet中调用时,CQ5 QueryBuilder不返回任何结果,servlets,aem,Servlets,Aem,我有一个从SlingAllMethodsServlet扩展而来的servlet,它使用QueryBuilder在存储库中的路径中搜索图像。当我执行servlet时,QueryBuilder返回0个结果,但是当我从CQ提供的querydebug.html运行相同的查询时,它返回预期的结果 我已将com.day.cq.search的日志级别设置为DEBUG,以尝试查找我的错误,但我在记录器中看到两次查询尝试的输出相同,只是servlet请求返回0个结果。以下是servlet调用的日志输出: GET

我有一个从SlingAllMethodsServlet扩展而来的servlet,它使用QueryBuilder在存储库中的路径中搜索图像。当我执行servlet时,QueryBuilder返回0个结果,但是当我从CQ提供的querydebug.html运行相同的查询时,它返回预期的结果

我已将com.day.cq.search的日志级别设置为DEBUG,以尝试查找我的错误,但我在记录器中看到两次查询尝试的输出相同,只是servlet请求返回0个结果。以下是servlet调用的日志输出:

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

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}
]
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']
GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query took 22 ms
GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl >> xpath query returned 0 results (counted)
GET /libs/cq/search/content/createAssetPages HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl entire query execution took 32 ms
下面是querydebug.html的输出:

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
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
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}
]
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']
GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl xpath query took 9 ms
GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl >> xpath query returned 206 results (counted)
GET /libs/cq/search/content/querydebug.html HTTP/1.1] com.day.cq.search.impl.builder.QueryImpl entire query execution took 45 ms
以下是在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 );

从日志中可以看到,servlet和querydebug运行的查询是相同的,所以我不知道为什么从servlet运行时没有得到任何结果。如果您有任何建议或建议,我们将不胜感激。

我认为这不是代码的问题。这可能与用户权限有关。我猜您是通过querydebug.html以admin的身份执行查询,而在servlet中,会话是由不同的用户执行的,或者不是由admin执行的。问题确实是权限问题。我使用了resolverFactory.getResourceResolver,而不是resolverFactory.GetAdministrativeSolver。一旦我改变主意,问题就解决了。谢谢你的提示!