Question

The Target is to perform multisort by score then distance, and to limit to a radius of 0.14 degrees I perform the following query:

localhost:8983/solr/coll1/select?sortsq={! score=distance}locations:"Intersects(Circle(34.0031792,-118.3082034 d=0.14))"&fl=score,distdeg:query($sortsq),*&facet=true&sort=score desc,query($sortsq) asc&indent=on&wt=xml&version=2.2&rows=10&start=0&q=text:*&facet.field=xxxxx&fq=fieldname:"filterValue"

All the documents matching the query are returned, whether it is within the circle or not, but the ones that within the 0.14 degrees returns the distance (distdeg), and the others does not have that field returned.

How can I omit the non-intersecting documents?

locations field declaration:

<fieldType name="geo_field"   class="solr.SpatialRecursivePrefixTreeFieldType"
               spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
               distErrPct="0.025"
               maxDistErr="0.000009"
               units="degrees"
 />

Update: Working Version of the query

http://localhost:8983/solr/coll1/select?getDist={! score=distance}locations:"Intersects(Circle(34.0031792,-118.3082034 d=0.14))"&fl=score,distdeg:query($getDist),*&facet=true&sort=score desc&indent=on&wt=xml&version=2.2&rows=10&start=0&q=*:*&boost=query({! score=distdeg filter=false v=$getDist)&fq=locations:"Intersects(Circle(34.0031792,-118.3082034 d=0.14))",states:"CA"
Was it helpful?

Solution

You aren't actually spatially filtering at all. A solr search matches documents based on the 'q' (the query string from the user; it scores) and 'fq' (filter queries, which don't score), nothing else. Neither your 'q' nor your 'fq' refers to the spatial filter that you put into the sortsq param. See the docs: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4#Search

Your q=text:* is weird; what do you intend? All docs? That query might appear to work but don't do that, as its not doing what you think its doing; it's finding all docs that have any value in that field (not fast to compute), which isn't necessary all docs. Best practice is defType=edismax and q.alt=*:* and qf=text (assuming that's your text search field) which will match all docs if you don't have a query string to supply.

By the way, it doesn't make any sense to follow score sorting with anything else. There are a huge variety of floating point values and consequently the distance will rarely be consulted. You probably want to boost scores by distance instead. Here's an example of that: &boost=query({! score=recipDistance filter=false v=$spatialfilter}) (substitute the name of your parameter that has the spatial search for spatialFilter).

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