Marklogic 如何在文档属性中搜索?

Marklogic 如何在文档属性中搜索?,marklogic,Marklogic,我想搜索文档的文档属性。我只在Marklogic中加载了文档,没有xml文件。我已关闭内容处理。现在我想搜索元数据(出现在xdmp:documentproperties(uri)中) 我在文档中具有以下属性:- <?xml version="1.0" encoding="UTF-8"?> <prop:properties xmlns:prop="http://marklogic.com/xdmp/property"> <uploaded>true</

我想搜索文档的文档属性。我只在Marklogic中加载了文档,没有xml文件。我已关闭内容处理。现在我想搜索元数据(出现在
xdmp:documentproperties(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>

但是,这是行不通的。请帮助。

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

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

Fwiw,还有一个XPath轴用于访问属性


属性约束的问题是,它只更改片段范围,而不接受名称属性来将搜索限制为一个属性。如果添加
true
,您将看到结果查询是什么

不过有几个选择

第一个选项是使用
属性
。您可以在顶层使用它将其应用于所有搜索约束,也可以在每个约束中仅影响特定约束。强制搜索查询在属性片段上运行,而不是在文档片段上运行,这是一种相对简单的方法。缺点是它不会影响搜索匹配,也就是代码片段

要影响代码片段,最好按照@mblakele的建议,使用可搜索表达式:
xdmp:document-properties()
。这实际上会影响代码段和搜索查询,因此使用它将导致您获取搜索代码段,并使查询在属性代码段上运行。不过,author约束仍然不限于您的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
)
xquery版本“1.0-ml”;
导入模块命名空间搜索=”http://marklogic.com/appservices/search"
位于“/MarkLogic/appservices/search/search.xqy”;
(:原始方法:)
让$options1:=
真的
让$results1:=search:search(“作者:管理员”,$options1,1,1)
(:使用片段作用域:)
让$options2:=
性质
真的
让$results2:=search:search(“作者:管理员”,$options2,1,1)
(:使用可搜索表达式:)
让$options 3:=
xdmp:document-properties()
真的
让$results3:=search:search(“作者:管理员”,$options3,1,1)
(:使用带有元素词约束的可搜索表达式:)
让$options4:=
xdmp:document-properties()
真的
让$results4:=search:search(“作者:管理员”,$options4,1,1)
返回(
$results1,
$results2,
$results3,
$results4
)
第四个例子应该给你你想要的结果

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
)