solrdistancespatialdismax

Solr get calculated distance while using dismax


I'm starting to think that what I want to do is not possible but thought I would give this a try.

I'm running Solr 3.5.

I currently have two types of search:

  1. A basic spatial query which returns the calulated distance between two points in the score field.

Sample Query from my Solr logs:

?fl=*,score&sort=score+asc&start=0&q={!func}geodist()&sfield=coordinates&pt=59.2363514,18.092783&version=2
  1. A dismax query which allows free text queries on a number of fields.

Sample Query from Solr log:

mm=1&d=100.0&sfield=coordinates&qf=field1^5.0+fields2^3.0&defType=edismax&version=2&fl=*,score&start=1&q=monkeyhopper&pt=59.2363514,18.0927830000&fq={!geofilt}}

I want to replace my first query with the dismax query but I really need to get the calculated distance in the response. Yes, I can calulate the distance programatically but I would prefer not having to do this as Solr has done it for me already.

I still want to be able to sort my dismax query "by relevance", distance or any other field so the score given by my boosts could be interesting for sorting but I don't need it to be returned.


Solution

  • Pseudo-fields are now available in Solr 4+ which allow you to do just this.

    http://localhost:8983/solr/collection1/browse?q=*:*&rows=1000&wt=xml&pt=37.763649,-122.24313&sfield=store&fl=dist:geodist()
    

    For instance, this request allows me to return a field "dist" which contains the distance of each entry to the stated point.