欢迎投稿

今日深度:

solr空间查询,

solr空间查询,


为什么80%的码农都做不了架构师?>>>   

由于在工作中使用到了solr的空间搜索功能,在此记录过程。

修改schema.xml文件

添加fieldType

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

添加field

<field name="latlon" type="location" indexed="true" stored="true"/>

2.修改data-config.xml

如,s_latitude_s 字段为经度,s_longitude_s 字段为维度

在data-config.xml加入如下脚本

<script><![CDATA[
                function f1(row){
                    var lat_coordinate = row.get("s_latitude_s");
                    var log_coordinate = row.get("s_longitude_s");
                    if(!isNaN(lat_coordinate) && !isNaN(log_coordinate) && lat_coordinate*1 >= -90  &&  lat_coordinate*1 <= 90 ) {
                    	  var store_lat_lon = lat_coordinate + "," + log_coordinate;
                    	  row.put("latlon",store_lat_lon);
                    }else{
                       row.put("latlon","0,0");
                    }
                    return row;
                }
]]></script>

在entity中引用该脚本 transformer="script:f1"

3.重启solr

4.查询示例

http://127.0.0.1:6230/goods/select/?q=*:*&fq={!geofilt}&sfield=latlon&pt=29.546327,106.530559&d=5&sort=geodist()%20asc

参数
描述 示例
d 范围,单位:千米 d=5
pt
搜索过滤的中心点,纬度,经度坐标点 pt=29.5454,106.5305
sfield 空间搜索类型的字段(eg: solr.LatLonType sfield=latlon
fq 设置查询过滤器 fq={!geofilt}
sort 根据字段或者函数排序 sort=geodist() asc


geofilt 函数:  使结果集约束在到中心点位置的最大距离(km)圆形区域内。

geodist 函数:   计算两点之间的距离。


转载于:https://my.oschina.net/jayhu/blog/368196

www.htsjk.Com true http://www.htsjk.com/solr/39375.html NewsArticle solr空间查询, 为什么80%的码农都做不了架构师?    由于在工作中使用到了solr的空间搜索功能,在此记录过程。 修改schema.xml文件 添加fieldType fieldType name="location" class="solr.LatLonType"...
相关文章
    暂无相关文章
评论暂时关闭