Reputation: 63619
I want to search a map within a bounding box whose lat/lng for North East points and South West points are available. I have lat
and lng
indexed as TrieDoubleField
type and latlng
as solr.LatLonType
type. The reason for searching within a box (and not a radius like in geofilt
) is because the search is done on all areas visible on a rectangular map , and I am given the coordinates of 4 corners of the map.
Problem: Will it be inefficient to do 2 range queries, one for lat
and one for lng
? As shown in the image below, a lot of unnecessary ranges have to be searched through.
http://127.0.0.1:8080/solr/select?q=*:*fl=id&fq=lat:[42.2823890429 TO 42.4224427748] AND lng:[-71.3345718384 TO -70.7612228394]
If so, is there a better way?
fq={!bbox}&sfield=latlng&pt=45.15,-93.85&
d=5
will not work as I cannot calculate the value for d
to match the bounds of my map.
Upvotes: 2
Views: 3935
Reputation: 4140
Solr 4 has a set of new spatial field types in which you can specify the lat-lon bounding box. There is information here which I intend to bring up to date this weekend.
If you are using Solr 3 then yes, you can just do numeric range queries as you are doing. If you want to handle a dateline cross then it's a little more tricky as there are two pairs of range queries needed for the longitude. And "no", this approach is not inefficient, as you asked. BTW you don't need to index the latitude & longitude separately since the LatLonType does this already and you can use its fields. Look in the schema browser and you should see a field ending in __x and __y (if I recall).
Upvotes: 4