Marklogic属性搜索 - XML元素数组

时间:2015-08-22 10:50:48

标签: marklogic

这是Marklogic

中文档的属性文件



<?xml version="1.0" encoding="UTF-8"?>
<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
  <type type="string" xmlns="http://marklogic.com/xdmp/json/basic">document</type>
  <project type="string" xmlns="http://marklogic.com/xdmp/json/basic">Eagle</project>
  <fileroom type="string" xmlns="http://marklogic.com/xdmp/json/basic">Fileroom3</fileroom>
  <documentTitle type="string" xmlns="http://marklogic.com/xdmp/json/basic">HadoopOperations</documentTitle>
  <uploadDate type="string" xmlns="http://marklogic.com/xdmp/json/basic">2015-08-21T12:45:19.138Z</uploadDate>
  <lastModified type="string" xmlns="http://marklogic.com/xdmp/json/basic">2015-08-21T12:45:19.138Z</lastModified>
  <numPages type="number" xmlns="http://marklogic.com/xdmp/json/basic">11</numPages>
  <users type="array" xmlns="http://marklogic.com/xdmp/json/basic">
    <item type="string">mreviewer1@merrill.com</item>
    <item type="string">madmin1@merrill.com</item>
  </users>
  <cpf:processing-status xmlns:cpf="http://marklogic.com/cpf">done</cpf:processing-status>
  <cpf:property-hash xmlns:cpf="http://marklogic.com/cpf">77ecfa8e87a5097e29b4d9846e131a67</cpf:property-hash>
  <cpf:last-updated xmlns:cpf="http://marklogic.com/cpf">2015-08-21T18:15:19.333+05:30</cpf:last-updated>
  <cpf:state xmlns:cpf="http://marklogic.com/cpf">http://marklogic.com/states/converted</cpf:state>
  <lnk:link from="/Eagle/Fileroom3/HadoopOperations_pdf_parts/" to="/Eagle/Fileroom3/HadoopOperations.pdf" rel="source" rev="conversion" strength="strong" xmlns:lnk="http://marklogic.com/cpf/links"/>
  <lnk:link from="/Eagle/Fileroom3/HadoopOperations_pdf.xhtml" to="/Eagle/Fileroom3/HadoopOperations.pdf" rel="source" rev="conversion" strength="strong" xmlns:lnk="http://marklogic.com/cpf/links"/>
  <cpf:self xmlns:cpf="http://marklogic.com/cpf">/Eagle/Fileroom3/HadoopOperations.pdf</cpf:self>
  <prop:last-modified>2015-08-21T18:15:23+05:30</prop:last-modified>
</prop:properties>
&#13;
&#13;
&#13;

我想写一个查询,我需要找到users属性所在的文件&#34; madmin1@merrill.com"。

db.documents.query(
        qb.where(
                qb.directory(directories),
                qb.propertiesFragment(
                        qb.value(
                                qb.element(
                                        qb.qname("http://marklogic.com/xdmp/json/basic", "users")
                                ),
                                qb.term("admin.merrill.com")
                        )
                )
        ).withOptions({
            queryPlan: true,
            metrics:true,
            debug:true})
).result(function(response){
    console.log(response);
});

输出:

    [ { 'snippet-format': 'snippet',
    total: 0,
    start: 1,
    'page-length': 10,
    results: [],
    plan: { 'query-plan': [Object] },
    report: '(cts:search(fn:collection(), cts:and-query((cts:directory-query("/Eagle/Fileroom1/", "1"), cts:properties-fragment-query(cts:element-value-query(fn:QName("http://marklogic.com/xdmp/json/basic","users"), "admin.merrill.com", ("lang=en"), 1))), ()), ("unfiltered",cts:score-order("descending")), 1))[1 to 10]',
    metrics: 
     { 'query-resolution-time': 'PT0.015S',
       'snippet-resolution-time': 'PT0S',
       'total-time': 'PT0.172S' } } ]

但是获得空阵列。请帮助纠正此查询。

2 个答案:

答案 0 :(得分:2)

您正在搜索admin.merrill.com,而您说要查找madmin1@merrill.com。在您旁边搜索jbasic:users元素,但是使用您的方法,您将寻找与该元素的完整字符串值匹配的值,其中包含多个邮件地址。

我建议为jbasic:users/jbasic:item添加路径范围索引(确保也添加命名空间),并将其用于匹配。您需要切换到路径范围查询以利用索引。

这也可以为您带来性能提升。范围查询通常比值查询执行得更好。

HTH!

答案 1 :(得分:0)

我相信它是 qb.properties()不是 qb.propertiesFragment()

来源:https://docs.marklogic.com/8.0/guide/node-dev/search