通过搜索/QueryBuilderAPI检索AEM页面属性
有没有办法通过QueryBuilderAPI检索作为页面元数据(页面属性)存储在单独JCR节点中的数据 例如: 搜索结果应该包括~/article-1/jcr:content/缩略图下的数据。但是,我得到的唯一结果是~article-1/jcr:content/content(模板中包含一个parsys)下的数据 一个示例查询:通过搜索/QueryBuilderAPI检索AEM页面属性,aem,Aem,有没有办法通过QueryBuilderAPI检索作为页面元数据(页面属性)存储在单独JCR节点中的数据 例如: 搜索结果应该包括~/article-1/jcr:content/缩略图下的数据。但是,我得到的唯一结果是~article-1/jcr:content/content(模板中包含一个parsys)下的数据 一个示例查询: http://localhost:4502/bin/querybuilder.json?p.hits=full&path=/content/path/to/a
http://localhost:4502/bin/querybuilder.json?p.hits=full&path=/content/path/to/articles
结果(代码片段):
搜索配置是现成的默认设置
编辑:返回JSON格式的数据,但在API中不可访问:
结果:
{
"success":true,
"results":2,
"total":2,
"offset":0,
"hits":[
{
"jcr:path":"/content/path/to/articles/article-a",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:27:01 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"jcr:lastModified":"Wed Dec 04 2013 12:10:47 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
},
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"fileReference":"/content/dam/path/to/IBMDemo/apparel/women/wsh005_shoes/WSH005_0533_is_main.jpg",
"jcr:lastModified":"Mon Dec 09 2013 17:57:58 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
}
]
}
实施代码:
searchCriteria.put("path", path);
searchCriteria.put("type", "cq:Page");
searchCriteria.put("p.offset", offset.toString());
searchCriteria.put("p.limit", limit.toString());
searchCriteria.put("p.hits", "full");
searchCriteria.put("p.properties", "thumbnail");
searchCriteria.put("p.nodedepth", "2");
PredicateGroup predicateGroup = PredicateGroup.create(searchCriteria);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
try {
ValueMap properties = hit.getProperties();
VFSearchResult res = new VFSearchResult();
res.setUrl(hit.getPath());
res.setImageUrl((String)properties.get("thumbnail"));
res.setTags((String[])properties.get("cq:tags"));
res.setTeaserText((String)properties.get("teaserText"));
res.setTitle((String)properties.get("jcr:title"));
searchResults.add(res);
} catch (RepositoryException rex) {
logger.debug(String.format("could not retrieve node properties: %1s", rex));
}
}
在查询中设置路径后,设置一个或多个属性过滤器,如本例所示:
type=cq:Page
path=/content/path/to/articles
property=jcr:content/thumbnail
property.operation=exists
p.hits=selective
p.properties=jcr:content/thumbnail someSpecificThumbnailPropertyToRetrieve
p.limit=100000
您可以在/libs/cq/search/content/querydebug.html
上设置它们,然后还可以使用它们来获取相同查询的JSON URL
查看以下示例:您可以使用
CURL
以HTML/JSON/XML
格式检索节点属性。您所要做的就是安装下载CURL,并从与CURL的.exe
文件相同的目录中从终端运行CURL命令
HTML示例:
C:\Users\****\Desktop>curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html
JSON示例:
**C:\Users\****\Desktop>**curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html.tidy.infinity.json
注意:
infinity
在上面的查询中确保递归地获取指定路径下每个节点的每个属性我确实需要使用p.hits=full和p.nodededepth=2来获取缩略图属性。使用p.hits=selective从JSON中的点击中删除所有数据。
**C:\Users\****\Desktop>**curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html.tidy.infinity.json