使用 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 的参考坐标系各不相同。我存的是百度坐标系。数据库和索引里可支持多种坐标系。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值