2013-05-31 39 views
3

考慮下面的XML:如何創建嵌套的Contraints?

<Record> 
    <Author> 
     <FirstName>David</FirstName> 
     <LastName>Raj</LastName> 
    </Author> 
    <Author> 
     <FirstName>Sim</FirstName> 
     <LastName>Son</LastName> 
    </Author> 
    <Editor> 
     <FirstName>Sandy</FirstName> 
     <LastName>John<LastName> 
    </Editor> 
</Record> 

在目前我使用element-query<Author>得到的值。

<constraint name="Author"> 
    <element-query ns="" name="Author" /> 
    {$OPTIONS} 
</constraint> 

我不想搜索或查詢<LastName>元素的值,但需要單獨Author元素的<FirstName>纔有價值。是否有可能爲此創建嵌套約束? 如果可能的話可以有人詳細說明嗎?

謝謝。

回答

3

Sofi:

您在查詢中提供了包含元素的標準,而不是在約束中。

在這種情況下,您將創建兩個約束:ContentOwnerType上的element-query約束和Description上的值約束。然後,在查詢中,ContentOwnerType的element-constraint-query應在Description中包含value-constraint-query

下面是element-constraint-query的文檔:

http://docs.marklogic.com/guide/search-dev/structured-query#id_64263

作爲替代方案,您可以定義包括ContentOwnerType和排除域代碼:

http://docs.marklogic.com/guide/admin/fields#id_78911

0

如果我們只需要證明名字

我們可以創建約束作者參照

名字(爲此我們需要在名字創建的索引)

<search:constraint name="Author"> 
    <search:range collation="http://marklogic.com/collation" type="xs:string" facet="true"> 
    <search:facet-option>ascending</search:facet-option> 
    <search:element ns="" name="FirstName"/> 
    </search:range> 
</search:constraint> 

或者

我們可以有作者路徑索引/名字,以保證名字是在只有作者。

<search:constraint name="Author"> 
    <search:range collation="http://marklogic.com/collation" type="xs:string" facet="true"> 
     <search:facet-option>ascending</search:facet-option> 
     <search:path-index>*:Author/*:FirstName</search:path-index> 
    </search:range> 
</search:constraint> 

希望這有助於:)