0

我有以下包含三个专利转让标签的 xml 文档

<patent-assignments>
    <patent-assignment>
     <patent-assignors>
        <patent-assignor>
          <name>TSAI, YU-WEN</name>
        </patent-assignor>
      </patent-assignors>
      <patent-assignees>
        <patent-assignee>
          <name>FARADAY TECHNOLOGY CORP.</name>
        </patent-assignee>
      </patent-assignees>
    </patent-assignment>

    <patent-assignment>
     <patent-assignors>
        <patent-assignor>
          <name>APPLE</name>
        </patent-assignor>
      </patent-assignors>
      <patent-assignees>
        <patent-assignee>
          <name>GOOGLE INC</name>
        </patent-assignee>
      </patent-assignees>
    </patent-assignment>

    <patent-assignment>
     <patent-assignors>
        <patent-assignor>
          <name>GOOGLE INC</name>
        </patent-assignor>
      </patent-assignors>
      <patent-assignees>
        <patent-assignee>
          <name>FARADAY TECHNOLOGY CORP.</name>
        </patent-assignee>
      </patent-assignees>
    </patent-assignment>
</patent-assignments>

现在,当我运行以下搜索查询时:-

 import module namespace search="http://marklogic.com/appservices/search" at 
"/Marklogic/appservices/search/search.xqy";

declare variable $options:=
    <options xmlns="http://marklogic.com/appservices/search">
    <transform-results apply="raw"/>
    </options>;

search:search("apple", $options, 1, 1)/search:result

我得到了完整的文档作为输出,但匹配的单词“APPLE”仅在 xml 的第二个专利转让标签中。我只想获得第二项专利转让作为输出而不是完整文档。如果我使用片段,那么它会显示找到匹配项的文档和元素名称,但它没有返回实际输出。我想要那个特定的专利转让标签作为找到匹配词的输出。

4

1 回答 1

3

Puneet,search:search 函数正在做它被配置做的事情,从这个意义上说,响应是正确的。你只需要对你要求它做的事情做一个小的改变。试试这个:

import module namespace search="http://marklogic.com/appservices/search" at 
  "/Marklogic/appservices/search/search.xqy";

declare variable $options:=
  <options xmlns="http://marklogic.com/appservices/search">
    <transform-results apply="raw"/>
    <searchable-expression>/patent-assignments/patent-assignment</searchable-expression>
  </options>;

search:search("apple", $options, 1, 1)/search:result

添加 searchable-expression 元素后,我只支持与查询匹配的专利转让元素:

<search:result index="1" uri="/patent.xml" path="fn:doc(&quot;/patent.xml&quot;)/patent-assignments/patent-assignment[2]" score="43008" confidence="0.664889" fitness="0.664889" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
  <patent-assignment>
    <patent-assignors>
      <patent-assignor>
        <name>APPLE</name>
      </patent-assignor>
    </patent-assignors>
    <patent-assignees>
      <patent-assignee>
        <name>GOOGLE INC</name>
      </patent-assignee>
    </patent-assignees>
  </patent-assignment>
</search:result>
于 2012-05-16T16:17:23.527 回答