2013-04-24 92 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