Reputation: 1048
I have the following xml structure
<patent-assignors>
<patent-assignor>
<name>VOLPENHEIN, ROBERT A.</name>
<execution-date>
<date>19841204</date>
</execution-date>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>PROCTER & GAMBLE COMPANY, THE</name>
<address-2>A CORP. OF OHIO</address-2>
<city>CINCINNATI</city>
<state>OHIO</state>
</patent-assignee>
</patent-assignees>
I want to create a Database field in Marklogic Server for patent-assignor
& patent-assignee
so that I can use cts:field-word-query
. But I want to search the name of patent-assignor and patent-assignee (both contain the same element "name
"). Can anyone tell me how can I map field for patent-assignor to patent assignor name and patent-assignee to patent assignee name so that I can use cts:field-word-query
on names of patent-assignor and patent-assignee. I want an exact match.
Upvotes: 3
Views: 433
Reputation: 20414
That doesn't really sound like a use case for a Field index. Just put an index on element 'name
', and both cases will be indexed in the same index. To make a distinction, wrap a word-query
or value-query
with an element-query
for the appropriate parent element.
Upvotes: 2
Reputation: 305
I think the comments above about making sure you understand the options available are all important to consider. If I understand your question correctly, MarkLogic can probably answer your search using only the "universal index".
Because both the assignor and assignee both use an element named "name
", querying both for an exact match is acutally quite simple (exact match usually implies a value-query
not a word-query
)
cts:element-value-query(xs:QName("name"), "VOLPENHEIN, ROBERT A.")
However if there are more "name
" elements in your data other than the assignor and assignee and you need to narrow down hits to only come from these an not other "name
" fields you could use element-queries
to restrict the search (to get this to scale well please make sure you have element-word-positions
and element-value-positions
settings in your database set to true)
cts:or-query((
cts:element-query( xs:QName("patent-assignor"),
cts:element-value-query(
xs:QName("name"),
"VOLPENHEIN, ROBERT A.")),
cts:element-query( xs:QName("patent-assignee"),
cts:element-value-query(
xs:QName("name"),
"VOLPENHEIN, ROBERT A."))
))
Fields can be very powerful with regards to isolating specific elements, especially when there are complex "includes" and "excludes" logic to follow. I think it is very likely you can keep things more flexible by just using the "universal index" to do the filtering at query-time.
Upvotes: 1