开发者

Filter / function query to compare distance with field value

开发者 https://www.devze.com 2023-04-11 17:48 出处:网络
Can anyone help me to write a function query which compares the distance between a fixed point (supplied in the query) and a point stored per document with a distance stored in that document?

Can anyone help me to write a function query which compares the distance between a fixed point (supplied in the query) and a point stored per document with a distance stored in that document?

I am new to Solr and beyond knowing I can't use a filter query and that I will presumably need to use geodist() and fieldvalue('location') and fieldval开发者_运维技巧ue('point') I don't know where to start! Any help would be appreciated!

I am using Solr 3.2.


Turns out I can use a filter query with a range function to solve this (Solr 1.4+). For this case I used:

...&fq={!frange+l=0+u=9999999}sub(DocDistance,geodist(DocLocation,lat,lng))

Which will get the distance between the input point and the point on the document, then subtract the distance stored on the document before filtering out those where this value is less than 0 (9999999 approx= infinity).

PHEW! That was hard work! HTH someone in future.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号