Reputation: 131
I have following xml file
<data>
<element attribute="10">element1</element>
<element attribute="7">element2</element>
</data>
I have created element range index on "element" and attribute range index on "attribute" and tried to execute following query :
cts:search(collection(), cts:and-query((
cts:element-range-query(xs:QName("element"), "=", "element1")
cts:element-attribute-range-query(xs:QName("element"), xs:QName("attribute"), "<=", 7)
)))
Now its giving me above fragment as result, but actually attribute of "element1" is 10 which is more than 7, so accordinly above fragment shouldn't come as result.
Please help.
Upvotes: 0
Views: 273
Reputation: 7842
The query is doing what it should. It matches fragments for which element=element1 and element/@attribute<=7. Both of those statements are true for the sample XML. They aren't true for the same element in that XML, but the query doesn't guarantee that.
The trick here is to remember that indexes point to fragments. In general that means an entire document matches, or doesn't. http://docs.marklogic.com/guide/search-dev/count_estimate#id_63216 touches on this topic, and http://developer.marklogic.com/blog/fragmented-thoughts might help too.
Getting the results you want might involve doing something clever by enabling various position indexes and wrapping your query in a cts:element-query
. Or you might reconsider your node names so that they are fragment-unique for this query. Or you might consider setting a fragment root - but I consider that a last resort.
Upvotes: 4