solr空间查询
2015-02-02 14:28
423 查看
由于在工作中使用到了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加入如下脚本
在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
geofilt 函数: 使结果集约束在到中心点位置的最大距离(km)圆形区域内。
geodist 函数: 计算两点之间的距离。
需要定义一个坐标形式的字段
修改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 |
geodist 函数: 计算两点之间的距离。
相关文章推荐
- MongoDB——地理空间索引和查询
- 使用openlayers3自带的功能,使用WFS对geoserver服务器进行空间查询
- ORACLE第一步- 创建表空间、用户、授权以及简单查询
- solr查询参数、语法、函数总结
- Sqlserver查询数据库文件大小和剩余空间
- Solr查询参数q
- solr 查询语句中需要转义的字符
- 创建、查询、修改带名称空间的 XML 文件的例子
- Oracle查询表空间使用情况
- MYSQL查询数据库表索引的硬盘空间占用
- Oracle 查询某个表所占空间
- MySQL空间查询(Geometry类)
- Flex开发ArcGIS问题集锦九:怎样使用QueryTask执行空间查询和属性查询
- Oracle 查询表空间大小
- Oracle查询表空间使用情况
- MongoDB的地埋空间数据存储、空间索引以及空间查询
- 查询SQL表占用空间(sp_spaceused 表名) 收藏
- solr中只查询某一个字段的设置与设置时间排序
- 空间查询
- Solr -- 查询语法/参数