我正在尝试在JCR SQL2中进行全文搜索。查询应返回所有至少包含一个包含搜索字符串的属性的节点,或者它们具有包含相同字符串属性的子节点。这是我到目前为止所做的:
select * from [nt:base] as t where ocm_classname = 'info.magnolia.cv.CurriculumVitae' and contains(t.*, 'java')
这解决了第一部分,选择了具有指定ocm_classname
的所有节点以及至少一个包含单词'java'的属性。但我无法弄清楚如何搜索没有包含单词'java'的属性但具有包含该单词属性的子节点的节点。例如,应找到此节点:
<sv:node sv:name="cv1362044004066">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="address" sv:type="String">
<sv:value>Chicago, IL</sv:value>
</sv:property>
<sv:property sv:name="currentDepartment" sv:type="String">
<sv:value>dotNet</sv:value>
</sv:property>
<sv:property sv:name="currentRole" sv:type="String">
<sv:value>Project Manager</sv:value>
</sv:property>
<sv:property sv:name="dateOfBirth" sv:type="Date">
<sv:value>1981-01-14T00:05:00.000-05:00</sv:value>
</sv:property>
<sv:property sv:name="id" sv:type="String">
<sv:value>1362044004066</sv:value>
</sv:property>
<sv:property sv:name="name" sv:type="String">
<sv:value>John Carpenter</sv:value>
</sv:property>
<sv:property sv:name="ocm_classname" sv:type="String">
<sv:value>info.magnolia.cv.CurriculumVitae</sv:value>
</sv:property>
<sv:node sv:name="skills">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="collection-element">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="level" sv:type="String">
<sv:value>Advanced</sv:value>
</sv:property>
<sv:property sv:name="name" sv:type="String">
<sv:value>Management</sv:value>
</sv:property>
<sv:property sv:name="ocm_classname" sv:type="String">
<sv:value>info.magnolia.cv.CVSkills</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="collection-element">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="level" sv:type="String">
<sv:value>Advanced</sv:value>
</sv:property>
<sv:property sv:name="name" sv:type="String">
<sv:value>Scrum</sv:value>
</sv:property>
<sv:property sv:name="ocm_classname" sv:type="String">
<sv:value>info.magnolia.cv.CVSkills</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="collection-element">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="level" sv:type="String">
<sv:value>Advanced</sv:value>
</sv:property>
<sv:property sv:name="name" sv:type="String">
<sv:value>Java</sv:value>
</sv:property>
<sv:property sv:name="ocm_classname" sv:type="String">
<sv:value>info.magnolia.cv.CVSkills</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="collection-element">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="level" sv:type="String">
<sv:value>Intermediate</sv:value>
</sv:property>
<sv:property sv:name="name" sv:type="String">
<sv:value>Spring</sv:value>
</sv:property>
<sv:property sv:name="ocm_classname" sv:type="String">
<sv:value>info.magnolia.cv.CVSkills</sv:value>
</sv:property>
</sv:node>
</sv:node>
</sv:code>
答案 0 :(得分:5)
您需要使用JOIN子句,但在WHERE子句中使用OR:
SELECT parent.*
FROM [nt:base] AS parent
INNER JOIN [nt:base] AS child ON ISCHILDNODE(child,parent)
WHERE parent.ocm_classname = 'info.magnolia.cv.CurriculumVitae'
AND ( CONTAINS(parent.*, 'java') OR CONTAINS(child.*,'java') )
这会创建两个选择器parent
和child
,并使用ISCHILDNODE
连接条件来确保child
选择器中的节点是parent
中节点的子节点{1}}选择器。然后,它使用OR条件在结果中包含包含'java'的父节点或包含'java'的子节点。