Hi Danny,
Version is
MarkLogic Server
Enterprise Edition
5.0-4.3
I can run the code you have there on the host and it works. I even changed it
to "fn:collection()" instead of "/Dave.xml".
I also tried just the element-query:
cts:element-query(fn:QName("http://www.lexis-nexis.com/lncr","titles"),
"people") and that works as well with "/Dave.xml".
So, I saved a doc from the database I'm testing the query in to the file system
and loaded that into the Documents DB, which is where /Dave.xml is, and now I
can get two hits.
(So, I imagine if I were to send you the actual document, you'd see the same
things as me.)
?????
Dave
From: [email protected]
[mailto:[email protected]] On Behalf Of Danny Sokolsky
Sent: Tuesday, September 09, 2014 11:53 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] cts:element-query
Hi Dave,
That works for me on 7.0-3. Are you sure document looks exactly like that?
Here is what I did:
xdmp:document-insert("/Dave.xml",
<lncr:doc xmlns:lncr="http://www.lexis-nexis.com/lncr">
<lncr:metadata>
<lncr:titles>
<lncr:title>People v. Johnson</lncr:title>
</lncr:titles>
</lncr:metadata>
</lncr:doc>);
cts:search(doc("/Dave.xml"),
cts:element-query(fn:QName("http://www.lexis-nexis.com/lncr","titles"),
cts:element-word-query(fn:QName("http://www.lexis-nexis.com/lncr","title"),
"people")
) )
That returns the document.
What version of MarkLogic?
-Danny
From:
[email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Steiner, David
J. (LNG-DAY)
Sent: Tuesday, September 09, 2014 7:52 AM
To: General Mark Logic Developer Discussion
([email protected]<mailto:[email protected]>)
Subject: [MarkLogic Dev General] cts:element-query
Must be doing something wrong because it feels like I'm following the
documentation nearly exactly.
Data:
<lncr:doc xmlns:lncr="http://www.lexis-nexis.com/lncr">
<lncr:metadata>
<lncr:titles>
<lncr:title>People v. Johnson</lncr:title>
</lncr:titles>
...
</lncr:doc>
This works:
cts:search(fn:doc(),
cts:element-word-query(fn:QName("http://www.lexis-nexis.com/lncr","title"),
"people")
)[1]
This doesn't:
cts:search(fn:doc(),
cts:element-query(fn:QName("http://www.lexis-nexis.com/lncr","titles"),
cts:element-word-query(fn:QName("http://www.lexis-nexis.com/lncr","title"),
"people")
)
)[1]
But it seems like it should...
>From the documentation:
The cts:element-query<http://docs.marklogic.com/cts:element-query> function
searches through a specified element and all of its children. It is used to
narrow the field of search to the specified element hierarchy, exploiting the
XML structure in the data. Also, it is composable with other
cts:element-query<http://docs.marklogic.com/cts:element-query> functions,
allowing you to specify complex hierarchical conditions in the
cts:query<http://docs.marklogic.com/cts:query> expressions.
For example, the following search against a Shakespeare database returns the
title of any play that has SCENE elements that have SPEECH elements containing
both the words 'room' and 'castle':
for $x in cts:search(fn:doc(),
cts:element-query(xs:QName("SCENE"),
cts:element-query(xs:QName("SPEECH"),
cts:and-query(("room", "castle")) ) ) )
return
($x//TITLE)[1]
This query returns the first TITLE element of the play. The TITLE element is
used for both play and scene titles, and the first one in a play is the title
of the play.
In fact, this doesn't work, but it seems like it should if in fact, "the
cts:element-query function searches through a specified element and all of its
children" as the documentation says.
cts:search(fn:doc(),
cts:element-query(fn:QName("http://www.lexis-nexis.com/lncr","titles"),
"people")
)[1]
I'm trying to build a query where I do different word searches at different
paths within the documents
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general