2
votes

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 fieldvalue('point') I don't know where to start! Any help would be appreciated!

I am using Solr 3.2.

1
It needs to be a 'continuous' function representing this logic: if(distance() - fieldValue > 0) return fieldValue; else return 0;Ian Grainger

1 Answers

4
votes

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.