Hi Mary,
The query looks for record with a first name but not a last name. Unless the
content is not empty, the last-name element is not present in the content. But
I need to check for both possibilities:
<record>
<child>
<first-name>Bob</first-name>
</child>
</record>
<record>
<child>
<first-name>Bob</first-name>
<last-name/>
</child>
</record>
The query is not working for the first example where no last-name element is
present.
Tim
From: [email protected]
[mailto:[email protected]] On Behalf Of Mary Holstege
Sent: 15 December 2016 12:15 PM
To: [email protected]
Subject: Re: [MarkLogic Dev General] cts;and-not-query working as expected
On 12/15/2016 08:26 AM, Tim Meagher wrote:
Hi folks,
The following query is looking for a record that contains a first but not last
name. The last name may or may not have an element associated with it. While I
believe I am using the proper syntax, I think the problem is due to the
fragment-oriented nature of using cts:and-not-query(), so I’m asking what
configuration needs to be in place. Note that child and parent elements share
the same sub-elements of first-name and last-name, hence the use of
cts:element-query, but there is only one child element per record I have tried
the following to no avail:
cts:search(/record,
cts:element-query(xs:QName("child"), cts:and-not-query(
cts:element-value-query(xs:QName("first-name"), ("*")),
cts:element-value-query(xs:QName("last-name"), ("*"))
))
)
cts:search(/record,
cts:element-query(xs:QName("child"), cts:and-not-query(
cts:element-value-query(xs:QName("first-name"), ("*")),
cts:element-query(xs:QName("last-name"), cts:and-query(()))
))
)
Do I need to create a fragment root for /record and add range indexes for
child, first-name, and last-name?
Range indexes are not used for element queries so they won't help you directly.
I also don't think adding fragments is really going to help, either.
I would look at the xdmp:plan for these searches: this tells you exactly what
query is running. You may run afoul of the issue that if the negated query
returns false positives, the and-not-query may return false negatives or it may
return false positives (depending on the details of the index settings and what
version you're running). You may run afoul of issues with wildcard queries,
depending, again, on your index settings. If this is an index resolution issue,
you may run afoul of not having the right positions on hand, or of the fact
that word positions depend the presence of words, and empty elements do not
have different positions from adjacent empty elements. Is the intent of this
query to find those documents with some first name but no last name element? or
no last name content? or neither?
Deconstructing a little: cts:element-value-query(xs:QName("last-name"),"*") is
a wildcarded value query and could only match if there is actually a last-name
element. cts:element-query(xs:QName("last-name"), cts:and-query()) also
affirmatively requires a last-name element but doesn't try to wildcard the
content. The element query asserts that matches of the and-not query are scoped
by the element-query.
What is going wrong -- false positives? false negatives? What does xdmp:plan
show?
Thanks for any help with this!
Tim Meagher
_______________________________________________
General mailing list
[email protected] <mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general