【问题标题】:How to search in document properties?如何在文档属性中搜索?
【发布时间】:2012-10-25 08:33:03
【问题描述】:

我想搜索文档的文档属性。我只在 Marklogic 中加载了文档,并且没有 xml 文件。我已关闭内容处理。现在我想搜索元数据(存在于xdmp:document-properties(uri)

我在文档中有以下属性:-

<?xml version="1.0" encoding="UTF-8"?>
<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
  <uploaded>true</uploaded>
  <OntologyResourceTypeValue>DOCUMENT</OntologyResourceTypeValue>
  <content-type>application/pdf</content-type>
  <filter-capabilities>text subfiles HD-HTML</filter-capabilities>
  <CreationDate>2002/12/05 09:44:29Z</CreationDate>
  <ModDate>2002/12/05 12:02:27+02'00'</ModDate>
  <Producer>Acrobat Distiller 5.0 (Windows)</Producer>
  <Author>Administrator</Author>
  <Creator>PScript5.dll Version 5.2</Creator>
</prop:properties>

现在我只想搜索作者而不是其他属性。如果我使用search:search("Administrator"),那么它会在整个文档中寻找这个词。但是,我只想在文档属性中搜索 Author 标签。同样,我也想搜索其他属性。

我也试过这个:-

let $options := <options xmlns="http://marklogic.com/appservices/search">
                          <constraint name="author">
                        <properties name="prop:Author"/>
                      </constraint>
                  </options>
    let $results := search:search("author:Administrator", $options, 1,  10)
    return  
    $results

但是,这不起作用。请帮忙。

【问题讨论】:

    标签: marklogic


    【解决方案1】:

    Fwiw,还有一个 XPath 轴可以访问属性。

    property::

    【讨论】:

      【解决方案2】:

      属性约束的问题在于,它仅更改片段范围,并且不接受名称属性来将搜索限制为仅一个属性。如果您添加&lt;return-query&gt;true&lt;/return-query&gt;,您会看到结果查询是什么。

      虽然有一些选择..

      第一个选项是使用&lt;fragment-scope&gt;properties&lt;/fragment-scope&gt;。您可以在顶层使用它来将其应用于所有搜索约束,也可以将每个约束应用于仅影响特定约束。这是强制搜索查询在属性片段而不是文档片段上运行的相对简单的方法。缺点是它不会影响搜索匹配,也就是 sn-ps。

      要影响 sn-ps,您最好按照@mblakele 的建议进行操作,并使用可搜索表达式:&lt;searchable-expression&gt;xdmp:document-properties()&lt;/searchable-expression&gt;。这实际上会影响 sn-ps 和搜索查询,因此使用它会导致您获得搜索 sn-ps,并让查询在属性片段上运行。不过,作者约束仍然不限于您的 Author 属性。

      一旦搜索遍及属性片段,将搜索限制在特定属性实际上非常简单。它和其他任何元素一样只是一个元素。使用元素词、值或范围约束来实现。

      下面一些代码来说明上面的内容:

      xquery version "1.0-ml";
      
      import module namespace search = "http://marklogic.com/appservices/search"
           at "/MarkLogic/appservices/search/search.xqy";
      
      (: original approach :)
      let $options1 :=
        <options xmlns="http://marklogic.com/appservices/search">
          <constraint name="author">
            <properties name="prop:Author"/>
          </constraint>
          <return-query>true</return-query>
        </options>
      let $results1 := search:search("author:Administrator", $options1, 1,  1)
      
      (: using fragment-scope :)
      let $options2 :=
        <options xmlns="http://marklogic.com/appservices/search">
          <fragment-scope>properties</fragment-scope>
          <constraint name="author">
            <properties name="prop:Author"/>
          </constraint>
          <return-query>true</return-query>
        </options>
      let $results2 := search:search("author:Administrator", $options2, 1,  1)
      
      (: using searchable-expression :)
      let $options3 :=
        <options xmlns="http://marklogic.com/appservices/search">
          <searchable-expression>xdmp:document-properties()</searchable-expression>
          <constraint name="author">
            <properties name="prop:Author"/>
          </constraint>
          <return-query>true</return-query>
        </options>
      let $results3 := search:search("author:Administrator", $options3, 1,  1)
      
      (: using searchable-expression with an element word constraint :)
      let $options4 :=
        <options xmlns="http://marklogic.com/appservices/search">
          <searchable-expression>xdmp:document-properties()</searchable-expression>
          <constraint name="author">
            <word>
              <element name="Author" ns="http://marklogic.com/xdmp/property"/>
            </word>
          </constraint>
          <return-query>true</return-query>
        </options>
      let $results4 := search:search("author:Administrator", $options4, 1,  1)
      
      return (
        $results1,
        $results2,
        $results3,
        $results4
      )
      

      第四个例子应该会给你想要的结果。

      HTH!

      【讨论】:

        【解决方案3】:

        我相信您还需要设置可搜索表达式。尝试添加此选项:

        <searchable-expression>xdmp:document-properties()</searchable-expression>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-06-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多