2013-04-24 89 views
1

我想搜索CQ 5.6(AEM)实例中包含的包含给定字符串xxx的所有.jsp文件的JCR存储库。作为JCR对XPath(或JCR-SQL2)解释的新手,我在表达查询方面不太成功。如何在jcr:content/@ jcr中搜索:使用JCR XPath的数据?

这将让我的所有.jsp文件:

//*[jcr:contains(., '.jsp')] 

这是我怎么会希望限制包含xxx.jsp文件上面的列表:

//*[jcr:contains(., '.jsp')][jcr:contains(jcr:content/@jcr:data, 'xxx')] 
//*[jcr:contains(., '.jsp') and jcr:contains(jcr:content/@jcr:data, 'xxx')] 
//*[jcr:contains(., '.jsp')]/jcr:content[jcr:contains(@jcr:data, 'xxx')]/.. 

@jcr:data存在Binary型。以上都不起作用。我哪里错了?

回答

4

它看起来像查询应该在nt:file节点上,而不是在jcr:data节点上。请参阅JCR - Jackrabbit - Xpath expression for search content text of a file contained inside a node的答案。

快速测试使用QueryBuilder的显示结果从JSP文件进来CQ(在这个例子中,他们含有 “/foundation/global.jsp”):

http://localhost:4502/bin/querybuilder.json?type=nt:file&nodename=*.jsp&group.1_fulltext=foundation/global.jsp 

给出:

{ 
    success: true, 
    results: 10, 
    total: 21, 
    offset: 0, 
    hits: [ 
    { 
     path: "/libs/cq/personalization/components/offerpage/body.jsp", 
     excerpt: " --%&gt;&lt;%@include file=&quot;/libs/<strong>foundation/global.jsp</strong>&quot;%&gt;&lt;% I18n i18n = new I18n(slingRequest); String icnCls = ...", 
     name: "body.jsp", 
     title: "body.jsp", 
     lastModified: "2013-04-24 11:45:05", 
     created: "2013-04-24 11:32:58", 
     size: "3 KB", 
     mimeType: "text/plain" 
    }, 
... 
} 
+0

这它。解决方案是编写'// * [jcr:contains(。,'.jsp')] [jcr:contains(jcr:content,'xxx')]'。虽然不是那么直观,但是... – 2013-04-24 13:16:10

+0

...是的,我没有想到querybuilder。思路不错 – 2013-04-24 13:31:57

+0

我试图运行一个类似的查询,但在JavaScript文件中搜索,但它不起作用,它应该是相同的情况,但我不明白为什么我得到零结果。 – ronnyfm 2016-06-27 17:26:19