XPath not() with path fields
22 November 2016 07:01 PM
Fields are a great way of restricting what parts of your documents to search, based on XML element QNames or JSON propertyNames . Fields are extremely useful when you have content in one or more elements or JSON properties that you want to query simply and efficiently as a single unit. But can you use field names you've created with XPath's fn:not ()? In other words, given a field name "test-field-name" can you do something like
The workaround is to create two fields, then to query across those two fields using
<title>John had a little lamb</title>
<title>Mary had a little lamb</title>
Say you're interested in three different paths:
1) All titles, Which Should be defined as fn:collection()//heading/title
2) Titles with lower-level titles, Which Should be defined as fn:collection()//hierlev[.//hierlev/heading/title]/heading/title
3) Titles with NO lower-level titles, Which Should be defined as fn:collection()//hierlev[fn:not(.//hierlev/heading/title)]/heading/title
Unfortunately, while we can express #3 in full XPath, we can not express #3 in the subset of XPath used to describe path fields. However, you can emulate #3 by defining fields corresponding to #1 & #2, then combining them in a cts:not-in-query.
Create the path fields
Create a Path Field with name "titles-all" path "//heading/title"
Create a Path Field with name "titles-with-lower-level titles," path "//hierlev[.//hierlev/heading/title]/heading/title"
Emulate the XPath you want by combining these two newly created path fields in a cts: not-in-query ()