In my documents there are two elements(<a> and <b>) on which range indexes(of the same type) exist. I want all those documents in which the values of <a> and <b> are same. I understand that using cts:element-value-co-occurrences()
I can fetch the pair of values of <a> and <b> from each fragment and compare the values. But how do I refer back to the fragment where a match is found? Or is there a simpler way to do this? All I want is the range indexes to get utilized.
Asked
Active
Viewed 304 times
5
1 Answers
3
The co-occurences functions return a list of all existing (within-fragment) value combinations of those two elements. If you simply look for all documents in which the value of element a is equal to the value of element b, you could do something like:
for $v in cts:element-values(xs:QName("a"))
return
cts:search(
collection(),
cts:and-query((
cts:element-value-query(xs:Qname("a"), $v),
cts:element-value-query(xs:Qname("b"), $v)
))
)
Or you could use cts:uris
instead of cts:search
to find the database uris of those docs..
ADDED:
What @mblakele in the comment below means is this:
let $query :=
cts:or-query(
for $v in cts:element-values(xs:QName("a"))
return
cts:and-query((
cts:element-value-query(xs:Qname("a"), $v),
cts:element-value-query(xs:Qname("b"), $v)
))
)
return
cts:search(
collection(),
$query
)
That saves you from doing cts:search for each value separately, and is likely to perform quicker..
HTH!

grtjn
- 20,254
- 1
- 24
- 35
-
You might also try building one big or-query with all the and-query terms, so you can call `cts:search` just once. That should be more efficient. – mblakele Jan 10 '14 at 18:00
-
Hmmm. So instead of the indexes being looked up every time the loop executes they are looked up only once. – callow Jan 13 '14 at 08:49
-
@callow: yes. There is one values lookup in the index. Then one big cts query is built from them in the loop. And only after the loop one final big search is performed against the index.. – grtjn Jan 14 '14 at 06:57
-
@grtjn by the way can you point me to a link that will give me detailed explanation of the co-occurences functions and their use cases. The API documentation says cts:element-value-co-occurrences() returns value co-occurrences (that is, pairs of values, **both of which appear in the same fragment**) from the specified element value lexicon(s). But apparently it returns a list of all existing value **combinations** of those two elements. So I am a bit confused . Also what if I,as I initially intended, want to find a list of (a,b) pairs from all the documents as they are present in them? – callow Jan 14 '14 at 08:49
-
I do not mean to divert the discussion of this thread . So if you could point me to an existing discussion that would be best. – callow Jan 14 '14 at 08:51
-
@callow: sounds like a relevant question to me. I think the explanation you found is correct though. The function should indeed return an accumulation of all unique within-fragment combinations, over all fragments you are searching through. Try creating three samples in a test database, and use document-query to test what is return for one and for more documents explicitly. – grtjn Jan 14 '14 at 15:33