I am performing a REDISEARCH tag search only query like this:
'@tags:{Food|Restaurant|Chicago}'
I would like to sort the result based on number of successful matches of these tags in the document.
So that:
Is this possible ? If so, please how can I perform such a sort ?
Thanks!
At current state, this isn't directly in the feature set of RediSearchemphasized text. Matching tags are not counted towards the score. An example:
127.0.0.1:6379> ft.create test SCHEMA mytags TAG
OK
127.0.0.1:6379> ft.add test one 1 FIELDS mytags "aa"
OK
127.0.0.1:6379> ft.add test two 1 FIELDS mytags "aa,bb"
OK
127.0.0.1:6379> ft.add test three 1 FIELDS mytags "aa,bb,cc"
OK
127.0.0.1:6379> ft.add test four 1 FIELDS mytags "aa,bb"
OK
When you query, add the WITHSCORES
argument:
127.0.0.1:6379> FT.SEARCH test "@mytags:{aa|bb|cc}" WITHSCORES
1) (integer) 4
2) "four"
3) "inf"
4) 1) "mytags"
2) "aa,bb"
5) "three"
6) "inf"
7) 1) "mytags"
2) "aa,bb,cc"
8) "two"
9) "inf"
10) 1) "mytags"
2) "aa,bb"
11) "one"
12) "inf"
13) 1) "mytags"
2) "aa"
The "inf"
is indicating that there is no score attributed to this match so the order is not taken into account here for scoring purposes.
I also attempted to do this with the aggregation engine and could not find a way to create a pipeline that would effectively count matched tags.
This seems like a straight forward use, I did file an issue for this.
A couple of workarounds:
TEXT
field and optional clauses ("~Food|~Restaurant|~Chicago"
), but a text field will have slightly different properties.