[英]Restrict the expansion of search for cts:element-value-search- Marklogic
I am using cts:element-value-search to search document based on the parameter.我正在使用 cts:element-value-search 根据参数搜索文档。 While the query works fine I want it to search elements in immediate children only.
虽然查询工作正常,但我希望它只搜索直接子元素中的元素。
For Ex.对于前。 My document tree looks like this
我的文档树看起来像这样
document1.xml文件1.xml
<Person>
<FirstName>Johnson</FirstName>
<LastName>W</LastName>
<EmailAddress>john@abc.com</EmailAddress>
<Neighbour>
<FirstName>Mathew</FirstName>
<LastName>Long</LastName>
</Neighbour>
</Person>
document2.xml文件2.xml
<Person>
<FirstName>Mathew</FirstName>
<LastName>W</LastName>
<EmailAddress>john@abc.com</EmailAddress>
<Neighbour>
<FirstName>Anderson</FirstName>
<LastName>Long</LastName>
</Neighbour>
</Person>
and my query is我的查询是
cts:search(
/Person,
cts:and-query((
cts:element-value-query(xs:QName("FirstName"), concat('*', "son", '*'),
("wildcarded", "case-insensitive", "whitespace-sensitive", "punctuation-sensitive"))
)),
()
)
This returns both the documents because for the first document it matches <FirstName>Johnson</FirstName>
这将返回两个文档,因为对于第一个文档,它与
<FirstName>Johnson</FirstName>
匹配
and for the second document it matches对于第二个文档,它匹配
<FirstName>Anderson</FirstName>
which is at the lower level.这是在较低的水平。
I do not want the second result and want the query to search at level 1 only.我不想要第二个结果,只希望查询在级别 1 进行搜索。
Any help is appreciated.任何帮助表示赞赏。
You can scope sub-queries to particular container elements or properties, using cts:element-query
, and cts:json-property-scope-query
.您可以使用
cts:element-query
和cts:json-property-scope-query
子查询范围限定为特定的容器元素或属性。 Those will trim down sub-query matches to a particular ancestor.这些将减少与特定祖先的子查询匹配。
cts:element-query(xs:QName('Person'), cts:element-value-query(xs:QName('Firstname', ...))
will not be enough however, as Neighbour/Firstname
is also a descendant. cts:element-query(xs:QName('Person'), cts:element-value-query(xs:QName('Firstname', ...))
还不够,因为Neighbour/Firstname
也是后代.
Simplest option is to use a path range index on Person/Firstname
.最简单的选择是在
Person/Firstname
上使用路径范围索引。 That is by far the most straight-forward solution here.这是迄今为止最直接的解决方案。
HTH!哼!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.