使用 Apache Lucene 和 Solr 进行位置感知搜索

http://wiki.apache.org/solr/SpatialSearch


有三点:

1. geofilt 一个点和距离 , 指定查询字段。返回数据

 

...&q=*:*&fq={!geofilt sfield=store}&pt=45.15,-93.85&d=5
...&q=*:*&fq={!geofilt}&sfield=store&pt=45.15,-93.85&d=5

2.bbox 一个半径为d 边框范围,
...&q=*:*&fq={!bbox}&sfield=store&pt=45.15,-93.85&d=5

3. geodist 排序方法。默认按照距离排序,还有比较复杂的用法没有研究,注意:
?q=*&fq={!geofilt%20sfield=baidu_geo}&pt=45.15,-93.85&d=5&sort=geodist()%20asc 这是错的,会报 sort param could not be parsed as a query, and is not a field that exists in the index: geodist()

?q=*&fq={!geofilt}&sfield=baidu_geo&pt=30.648694,104.091852&d=5&sort=geodist()%20asc  这是对的


http://wiki.apache.org/solr/SpatialSearchDev 有配置的实例,但是注意:

Example

 

<fieldType name="latLon" class="solr.LatLonType" subFieldSuffix="_latLon"/>
...
<field name="store_lat_lon" type="latLon" indexed="true" stored="true"/>
...
<dynamicField name="*_latLon" type="double" indexed="true" stored="false" multiValued="true"/>
这是错的,http://wiki.apache.org/solr/SpatialSearch 有描叙 :

The LatLonType is the current default spatial field. Values for this type are of the form latitude,longitude, although behind the scenes, the latitude and longitude are indexed as separate numbers. Fields using LatLonType must be single valued (i.e. multiValued="false"). This field type does distance calculations based on Great Circle (haversine).

In addition to  geofiltgeodist and  bbox, the LatLonType supports field queries such as  field:10,20 and range queries such as  field:[10,20 TO 30,40].

正确的 schema.xml 配置是:

<fieldtype name="latLon" class="solr.LatLonType"/>
<field name="geo" type="latLon"  stored="true" indexed="true"/>
<dynamicField name="*_latLon" type="double" indexed="true" stored="false" multiValued="false"/>


坐标系转换

因为中国法律规定, 原始gps地图坐标不能得到, 而 goods,baidu, sogo 的参考坐标系各不相同。我存的是百度坐标系。数据库和索引里可支持多种坐标系。

猜你喜欢

转载自sb122k.iteye.com/blog/1585035