Vedavalli,
I think I understand - you need multiple conditions to match in one element and
not have false positives from other elements throw off cts:uris() and other
unfiltered operations.
The query below works on my machine *but only if adequate "position" indexes
are turned on for the database*. I turned on word position, element word
positions and element value positions.
let $b :=
<root>
<detail>
<name>bookname</name>
<value>Hamlet</value>
</detail>
<detail>
<name>author</name>
<value>Shakespeare</value>
</detail>
</root>
return xdmp:document-insert("/test/book.xml", $b)
; (: transaction separator :)
let $q :=
cts:element-query(xs:QName("detail"),
cts:and-query( (
cts:element-value-query(xs:QName("name"), "author"),
cts:element-value-query(xs:QName("value"), "Hamlet")
) )
)
return cts:search(doc(), $q, "unfiltered")
The core question for you is filtering vs. not. This query with positional
indexes can exclude all false matches during "index resolution" so no false
positives are eliminated during "filtering" and therefore you can run
unfiltered searches or cts:uris() and get accurate results.
Note that cts:uris() only pulls data from the URI lexicon, so it is very fast
but you will need to later call doc($uir) to get real data from the document -
it may be faster and easier to use cts:search() which pulls the full document
right away.
Also note that it is much better to have XML like this if you possibly can:
<item>
<book>Hamlet</book>
<author>Shakespeare</author>
</item>
For efficiency, ease of coding and human readability.
Yours,
Damon
--
Damon Feldman
Sr. Principal Consultant, MarkLogic
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Vedavalli Radhika
Sent: Wednesday, February 13, 2013 4:18 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Somebody please help me!
Damon,
As mentioned by Raghu, below is the format of the xml stored in our database.
There can be multiple detail elements with name/value elements as children.
We have a requirement to achieve filtering based on the supplied name/value
pair entries.
Say for the below xmls, if I filter as name:bookname and value:Shakespeare, I
expect only the second xml to be returned back.
This works as expected when cts:search is used. But with cts:uris, both the
xmls are returned back. When we performed a response time comparison between
cts:search and cts:uris, cts:uris performs better.
This is when we started to look out for options to achieve the above
functionality with cts:uris. Can you advise on how we can achieve this with
cts:uris or a better performing api than cts:search?
Sample 1:
<root>
<detail>
<name>bookname</name>
<value>Hamlet</value>
</detail>
<detail>
<name>author</name>
<value>Shakespeare</value>
</detail>
</root>
Sample 2:
<root>
<detail>
<name>bookname</name>
<value>Shakespeare</value>
</detail>
<detail>
<name>author</name>
<value>Michael Wood</value>
</detail>
</root>
Thanks,
Radhika.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general