Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing element values from the same fragment using range index

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.

like image 562
callow Avatar asked Oct 21 '22 17:10

callow


1 Answers

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!

like image 139
grtjn Avatar answered Oct 23 '22 23:10

grtjn