Search code examples
solrlucenefilteringgeospatial

Solr - Using the Result of a Raw Query Param Function in a Filter (fq)


I am trying to work with a function's results like the measure of distance.

I have a raw query param

distance=query({!func v='mul(geodist(store_location,45.98,-110.65),1.60934)'})

I know I can use it as a field by having it in the query string as

fl=*,distance:$distance

Is there an equivalent to using it in the fq param? Using it like

fq=$distance:[0 TO 100]
# or
fq=distance:[0 TO 100]

doesn't seem to work. Is there another syntax for accessing this custom value of the document and filtering on it? The overall goal is to filter out results past a certain mileage range. Then I should be able to get a count of all the docs within the result.


Solution

  • You can do this using the geofilt query parser, and get the computed geodist() in fl :

    q=*:*&fq={!geofilt}&sfield=store_location&pt=45.98,-110.65&d=160.934&fl=*,geodist()