0
votes

I have the following xml document containing three patent-assignment tags

<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>

Now when I run the following search query:-

 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

I get the full document as the output but matching word "APPLE" is in only second patent-assignment tag of the xml. I want to get only second patent-assignment as the output not the full document. If I use snippets then it shows the document and element name where it finds the match but it did not return the actual output. I want that particular patent-assignment tag as the output where the matching word is found.

1

1 Answers

3
votes

Puneet, the search:search function is doing exactly what's it's been configured to do, and in that sense the response is correct. You just need to make a small change to what you're asking it to do. Try this:

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

After adding the searchable-expression element, I back just the patent-assignment element that matches the query:

<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>