How to create element range index in Marklogic?

孤者浪人 提交于 2019-12-07 17:09:22

问题


I have the following xml:-

<?xml version="1.0" encoding="UTF-8"?>
<patent-assignment>
  <assignment-record>
    <correspondent>
      <name>NORTH AMERICA INTERNATIONAL PATENT OFFIC</name>
      <address-1>P.O. BOX 506</address-1>
      <address-2>MERRIFIELD, VA 22116</address-2>
    </correspondent>
   </assignment-record>
  <patent-assignors>
    <patent-assignor>
      <name>TSAI, YU-WEN</name>
      <execution-date>
    <date>20050331</date>
      </execution-date>
    </patent-assignor>
    <patent-assignor>
      <name>HUANG, CHENG-I</name>
      <execution-date>
    <date>20050331</date>
      </execution-date>
    </patent-assignor>
  </patent-assignors>
  <patent-assignees>
    <patent-assignee>
      <name>FARADAY TECHNOLOGY CORP.</name>
      <address-1>NO.10-2, LI-HSIN ROAD 1, SCIENCE-BASED INDUSTRIAL PARK</address-1>
      <city>HSIN-CHU CITY</city>
      <country-name>TAIWAN</country-name>
    </patent-assignee>
  </patent-assignees>
 </patent-assignment>

Now I want to create range element indexes on names of patent-Assignor and patent-Assignee. But in Marklogic there is no option to specify XPath for range indexes. It will just take the index name as "name". So what will be the proper way to create element range indexes on names of patent-Assignor and patent-Assignee ?


回答1:


Puneet, in order to get just one set of names, MarkLogic needs to be able to distinguish between the sets somehow. Your best bet is to change the name element's localname (currently "name") or namespace (currently none) during ingest. After doing so, you can build an element-range-index and use cts:element-values(). For instance:

<?xml version="1.0" encoding="UTF-8"?>
<patent-assignment>
  <assignment-record>
    <correspondent>
      <name>NORTH AMERICA INTERNATIONAL PATENT OFFIC</name>
      <address-1>P.O. BOX 506</address-1>
      <address-2>MERRIFIELD, VA 22116</address-2>
    </correspondent>
  </assignment-record>
  <patent-assignors xmlns="http://puneet/assignors">
    <patent-assignor>
      <name>TSAI, YU-WEN</name>
      <execution-date>
        <date>20050331</date>
      </execution-date>
    </patent-assignor>
    <patent-assignor>
      <name>HUANG, CHENG-I</name>
      <execution-date>
        <date>20050331</date>
      </execution-date>
    </patent-assignor>
  </patent-assignors>
  <patent-assignees xmlns="http://puneet/assignees">
    <patent-assignee>
      <name>FARADAY TECHNOLOGY CORP.</name>
      <address-1>NO.10-2, LI-HSIN ROAD 1, SCIENCE-BASED INDUSTRIAL PARK</address-1>
      <city>HSIN-CHU CITY</city>
      <country-name>TAIWAN</country-name>
    </patent-assignee>
  </patent-assignees>
</patent-assignment>

From this XML, you can build a range index on each of the "name" elements, then call

cts:element-values(fn:QName("http://puneet/assignees", "name"))

to get the assignee names.




回答2:


You can use cts:path-range-query() for patent-assignors and patent-assignee

  1. cts:path-range-query("/patent-assignors/patent-assignor","=",$name)
  2. cts:path-range-query("/patent-assignees/patent-assignor","=",$name)



回答3:


You don't need to worry about the parent or ancestors of the element. You can restrict a element-range-query or element-value-query on an ancestor by wrapping it in an element-query:

cts:element-query(xs:QName("patent-assignor"), cts:element-value-query(xs:QName("name"), "my value"))

You can search on names with different ancestors in a single call by passing in a sequence as first param to cts:element-query:

cts:element-query((xs:QName("patent-assignor"), xs:QName("patent-assignee")), cts:element-value-query(xs:QName("name"), "my value"))

HTH!



来源:https://stackoverflow.com/questions/10578706/how-to-create-element-range-index-in-marklogic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!