CBLView Query returns wrong results


#1

Hi,
I have CBLView which emits below array as key
[string, int (range 1 to 3 only), string, date]

I am querying that view with
query.descending = true
query.startKey = [string1, 3, string2, []]
query.endKey = [string1, 1, string2]

Results totally ignores string2 in matching. If however I put 1 as second parameter in both start and end key then result matches string2 as well.

Could you please suggest what am I doing wrong?

I need to keep the integer range as second in key array as I have another query in which string2 is unknown and need results using int which runs fine with this view.


#2

Arrays are sorted hierarchically. The first items are compared, and if those are equal the second items are compared, etc. The effect in a view index is as though the first item is the primary key, the second is the secondary key, etc.

In other words, you can’t use the items as independent search ranges. It just doesn’t work that way.