2012-11-05 119 views
5

我想搜索文档的文档属性。我只有加载了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"),那么它在整个文档中查找这个单词。但是,我只想搜索文档属性中的作者标签。同样我也想在其他属性中搜索。

我也试过这样: -

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 

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

回答

0

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

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

Fwiw,还有一个XPath轴来获取属性。

property::

0

与性能约束的问题是,它只是改变了片段范围,并且不接受name属性将搜索范围限制到只有一个属性。如果你添加<return-query>true</return-query>你会看到结果查询是什么。

有虽然几个选项..

第一种选择是使用<fragment-scope>properties</fragment-scope>。您可以在顶层使用它来将其应用于所有搜索约束,并且还可以根据每个约束来仅影响特定约束。这是一种相对简单的方法,可以强制搜索查询运行属性片段,而不是通过文档片段。但不利的一面是,它不会影响搜索匹配,即片段。

要影响片段,您最好使用@mblakele建议的内容,并使用searchable-expression:<searchable-expression>xdmp:document-properties()</searchable-expression>。这实际上会影响片段和搜索查询,因此使用它会让您获取搜索片段,并让查询在属性片段上运行。尽管作者约束仍然不限制您的作者属性。

一旦搜索运行在属性片段上,限制搜索到一个特定的属性实际上是非常简单的。它只是其他任何元素。使用元素单词,值或范围约束来使其工作。

下面一些代码来说明上面:

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!