Question

So I've implemented and successfully used Solr 4. I've got to say that Solr 4 is awesome! Anyway I successfully sorted by distance and used a geofilter to limit the results to a certain area. What I would like to do now is boost the relevancy score by the inverse of the distance. This page talks about it but doesn't say how to do it (http://wiki.apache.org/solr/SpatialSearch)

I've tried the following but it gives me an error:

http://localhost:8983/solr/select/?q={!boost b=recip(geodist(), 1, 1000, 1000)}...

The error I get is:

org.apache.lucene.queryParser.ParseException: Expected identifier at pos 27 str='{!boost b=recip(geodist(), 1, 10 in ...

Any help would be appreciated. Thanks!

Was it helpful?

Solution

You still need to specify the main part of your query after the boost function:

q={!boost b=recip(geodist(),1,1000,1000)}foo:bar&...

If you're only interested in boosting by the inverse of the distance you can use a wildcard query:

q={!boost b=recip(geodist(),1,1000,1000)}*&...

...or use the function query parser:

q={!func}recip(geodist(),1,1000,1000)&...

You also need to specify the lat/long values and spatial field to query against either as arguments of the geodist function:

q={!boost b=recip(geodist(50.1, -0.86, myGeoField),1,1000,1000)}foo:bar&...

...or factored out as query string parameters:

q={!boost b=recip(geodist(),1,1000,1000)}foo:bar&sfield=myGeoField&pt=50.1,-0.86

OTHER TIPS

Just to add that i get better results with...

{!boost b=recip(geodist(),1,100,10)}

I don't know what causes this, but I wish Solr gave a little more information on the parameters for the recip and boost. Current Documentation is lacking.

As a side note, here is a distance boost used at my place of work. It's different than the one on the Solr documentation site. This boost function will treat distance equally for a number of kilomteres before the boosting begins. This is useful in some situations, where you don't want relevancy changes for small differences in distances.

You can change the constant 25 to be any number of kilometers that you want the boost to be the same.

You can define the distance boost as such:

div(1.0, min(1000, max(25, geodist())))

distance boost plot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top