简体   繁体   中英

Geospatial search within a bounding box using Solr

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.

在此处输入图片说明

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM