2

我正在尝试在 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>
4

1 回答 1

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

这将创建两个选择器parentchild,并使用ISCHILDNODE连接条件来确保child选择器中的节点是选择器中节点的子节点parent。然后,它使用 OR 标准将包含“java”的父节点或包含“java”的子节点包含在结果中。

于 2013-02-28T15:08:37.043 回答