在 RediSearch 中使用 GEOFILTER 时,如何先按一些数字字段(例如按价格)然后按距离对结果进行排序?
问问题
122 次
1 回答
3
FT.SEARCH命令不支持带有 SORTBY 的多个字段。
但是,您可以为此使用FT.AGGREGATE命令和geodistance函数。
下面是一个使用 REDIS-CLI 的示例:
HSET doc1 price 9.99 location "-122.41,37.77"
(integer) 0
HSET doc2 price 19.99 location "-122.40,37.78"
(integer) 0
HSET doc3 price 19.99 location "-122.42,37.79"
(integer) 0
FT.CREATE idx SCHEMA price NUMERIC SORTABLE location GEO SORTABLE
OK
FT.AGGREGATE idx "@price:[0 100]" APPLY 'geodistance(@location, "-122.39,37.78")' AS dist SORTBY 4 @price DESC @dist ASC
1) (integer) 3
2) 1) "location"
2) "-122.40,37.78"
3) "dist"
4) "879.1"
5) "price"
6) "19.99"
3) 1) "location"
2) "-122.42,37.79"
3) "dist"
4) "2862.08"
5) "price"
6) "19.99"
4) 1) "location"
2) "-122.41,37.77"
3) "dist"
4) "2080.58"
5) "price"
6) "9.99"
于 2021-10-22T09:23:09.127 回答