Puneet Pant
Puneet Pant

Reputation: 1048

How to create element range index in Marklogic?

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 ?

Upvotes: 3

Views: 1444

Answers (3)

Nikunj Vekariya
Nikunj Vekariya

Reputation: 833

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)

Upvotes: 3

Dave Cassel
Dave Cassel

Reputation: 8422

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.

Upvotes: 2

grtjn
grtjn

Reputation: 20414

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!

Upvotes: 2

Related Questions