博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
solr实现满足指定距离范围条件的搜索
阅读量:6799 次
发布时间:2019-06-26

本文共 9561 字,大约阅读时间需要 31 分钟。

配置schema.xml

  1 
<?
xml version="1.0" encoding="UTF-8" 
?>
  2 
<
schema 
name
="aifang-loupan"
 version
="1.1"
>
  3     
<
types
>
  4         
<
fieldType 
name
="string"
 class
="solr.StrField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
  5         
<
fieldType 
name
="boolean"
 class
="solr.BoolField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
  6         
<
fieldType 
name
="integer"
 class
="solr.IntField"
 omitNorms
="true"
/>
  7 
  8         
<
fieldType 
name
="int"
 class
="solr.TrieIntField"
 precisionStep
="0"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
  9         
<
fieldType 
name
="float"
 class
="solr.TrieFloatField"
 precisionStep
="0"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 10         
<
fieldType 
name
="long"
 class
="solr.TrieLongField"
 precisionStep
="0"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 11         
<
fieldType 
name
="double"
 class
="solr.TrieDoubleField"
 precisionStep
="0"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 12 
 13         
<
fieldType 
name
="tint"
 class
="solr.TrieIntField"
 precisionStep
="8"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 14         
<
fieldType 
name
="tfloat"
 class
="solr.TrieFloatField"
 precisionStep
="8"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 15         
<
fieldType 
name
="tlong"
 class
="solr.TrieLongField"
 precisionStep
="8"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 16         
<
fieldType 
name
="tdouble"
 class
="solr.TrieDoubleField"
 precisionStep
="8"
 omitNorms
="true"
 positionIncrementGap
="0"
/>
 17 
 18         
<
fieldType 
name
="sint"
 class
="solr.SortableIntField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
 19         
<
fieldType 
name
="slong"
 class
="solr.SortableLongField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
 20         
<
fieldType 
name
="sfloat"
 class
="solr.SortableFloatField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
 21         
<
fieldType 
name
="sdouble"
 class
="solr.SortableDoubleField"
 sortMissingLast
="true"
 omitNorms
="true"
/>
 22 
 23         
<
fieldType 
name
="date"
 class
="solr.TrieDateField"
 omitNorms
="true"
 precisionStep
="0"
 positionIncrementGap
="0"
/>
 24         
<
fieldType 
name
="tdate"
 class
="solr.TrieDateField"
 omitNorms
="true"
 precisionStep
="6"
 positionIncrementGap
="0"
/>
 25         
<
fieldtype 
name
="ignored"
 stored
="false"
 indexed
="false"
 class
="solr.StrField"
/>
 26        
<fieldtype name="location" class="solr.LatLonType" subFieldSuffix="_d"/>
    
 27         
<
fieldType 
name
="text"
 class
="solr.TextField"
 positionIncrementGap
="100"
>
 28               
<
analyzer 
type
="index"
>
 29                 
<
tokenizer 
class
="solr.StandardTokenizerFactory"
/>
 30                 
<
filter 
class
="solr.StopFilterFactory"
 ignoreCase
="true"
 words
="stopwords.txt"
 enablePositionIncrements
="true"
 
/>
 31                 
<
filter 
class
="solr.LowerCaseFilterFactory"
/>
 32               
</
analyzer
>
 33               
<
analyzer 
type
="query"
>
 34                 
<
tokenizer 
class
="solr.StandardTokenizerFactory"
/>
 35                 
<
filter 
class
="solr.StopFilterFactory"
 ignoreCase
="true"
 words
="stopwords.txt"
 enablePositionIncrements
="true"
 
/>
 36                 
<
filter 
class
="solr.SynonymFilterFactory"
 synonyms
="synonyms.txt"
 ignoreCase
="true"
 expand
="true"
/>
 37                 
<
filter 
class
="solr.LowerCaseFilterFactory"
/>
 38               
</
analyzer
>
 39         
</
fieldType
>
 40     
 41     
</
types
>
 42 
 43     
<
fields
>
 44         
<
field 
name
="loupan_id"
 type
="integer"
 indexed
="true"
 stored
="true"
 required
="true"
/>
 45         
<
field 
name
="city_id"
 type
="integer"
 indexed
="true"
 stored
="false"
/> 
 46         
<
field 
name
="loupan_name"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 47         
<
field 
name
="loupan_pinyin"
 type
="string"
 indexed
="true"
 stored
="false"
/>
 48         
<
field 
name
="alias_name"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 49         
<
field 
name
="former_name"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 50         
<
field 
name
="region_title"
 type
="text"
 indexed
="true"
 stored
="false"
 
/>
 51         
<
field 
name
="region_id"
 type
="int"
 indexed
="true"
 stored
="false"
/>
 52         
<
field 
name
="sub_region_title"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 53         
<
field 
name
="sub_region_id"
 type
="int"
 indexed
="true"
 stored
="false"
/>
 54         
<
field 
name
="regions_string"
 type
="string"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 55         
<
field 
name
="address"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 56         
<
field 
name
="proxy_address"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 57         
<
field 
name
="chanquan"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 58         
<
field 
name
="build_type"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 59         
<
field 
name
="property_type"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 60         
<
field 
name
="fitment_type"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 61         
<
field 
name
="search_kw"
 type
="text"
 indexed
="true"
 multiValued
="true"
 stored
="false"
 
/>  
 62         
<
field 
name
="investor"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 63         
<
field 
name
="company"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 64         
<
field 
name
="loop_line"
   type
="text"
  indexed
="true"
 stored
="false"
 
/>     
 65         
<
field 
name
="status_sale"
 type
="integer"
 indexed
="true"
 stored
="false"
/>
 66         
<
field 
name
="status_disp"
 type
="integer"
 indexed
="true"
 stored
="false"
/>
 67         
<
field 
name
="search_sale"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 68         
<
field 
name
="jiaofang_date"
 type
="sint"
 indexed
="true"
 stored
="false"
/>
 69         
<
field 
name
="kaipan_date"
 type
="sint"
 indexed
="true"
 stored
="false"
/>
 70         
<
field 
name
="price"
 type
="sint"
 index
="true"
 stored
="false"
/>
 71         
<
field 
name
="baidu_lat"
   type
="sfloat"
  indexed
="true"
 stored
="false"
/>
 72         
<
field 
name
="baidu_lng"
   type
="sfloat"
  indexed
="true"
 stored
="false"
/>
 73         
<
field 
name
="lat"
  type
="sfloat"
  indexed
="true"
  stored
="false"
/>
 74         
<
field 
name
="lng"
  type
="sfloat"
  indexed
="true"
  stored
="false"
/>
 75         
<
field 
name
="metro_subway_id"
  type
="integer"
 indexed
="true"
  stored
="false"
 multiValued
="true"
 
/>
 76         
<
field 
name
="metro_station_id"
 type
="integer"
 indexed
="true"
  stored
="false"
 multiValued
="true"
 
/>
 77         
<
field 
name
="metro_enabled"
    type
="integer"
 indexed
="true"
  stored
="false"
/>
 78         
<
field 
name
="metro_info"
       type
="text"
  indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 79        
<
field 
name
="loop_line_id"
 type
="integer"
 indexed
="true"
 stored
="false"
/>
 80        
<
field 
name
="property_type_id"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 81        
<
field 
name
="build_type_id"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 82        
<
field 
name
="fitment_type_id"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 83        
<
field 
name
="developer_id"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 84        
<
field 
name
="developer_title"
 type
="string"
 indexed
="true"
 stored
="false"
/>
 85        
<
field 
name
="business_id"
 type
="integer"
 indexed
="true"
 stored
="false"
/>
 86        
<
field 
name
="business_title"
 type
="string"
 indexed
="true"
 stored
="false"
/>
 87        
<
field 
name
="loupan_extend_type"
 type
="sint"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
 88         
<
field 
name
="trip_fitment_style"
 type
="text"
 indexed
="true"
 stored
="false"
 
/>
 89         
<
field 
name
="trip_feature_recommend"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 90         
<
field 
name
="trip_spot"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 91         
<
field 
name
="trip_transport"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 92         
<
field 
name
="trip_scenic_region"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 93         
<
field 
name
="trip_property_service"
 type
="text"
 indexed
="true"
 stored
="false"
 multiValued
="true"
 
/>
 94         
<
field 
name
="trip_scenic_spot"
 type
="text"
 indexed
="true"
 stored
="false"
/>
 95         
<
field 
name
="trip_created"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>
 96         
<
field 
name
="is_trip"
 type
="int"
 indexed
="true"
 stored
="false"
 
/>
 97         
<
field 
name
="level"
 type
="sint"
 indexed
="true"
 stored
="false"
/>
 98         
<
field 
name
="loupan_pv_day"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>
 99         
<
field 
name
="operator_ids"
 type
="integer"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
100         
<
field 
name
="operator_names"
 type
="string"
 indexed
="true"
 stored
="false"
 multiValued
="true"
/>
101         
<
dynamicField 
name
="*_grade"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>
102         
<
field 
name
="updated"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>  
103         
<
field 
name
="news_id"
 type
="int"
 indexed
="true"
 stored
="false"
 
/>  
104         
<
field 
name
="news_update"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>  
105         
<
field 
name
="rank"
 type
="sfloat"
 indexed
="true"
 stored
="false"
 
/>
106         
<
field 
name
="sale_order"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>
107         
<
field 
name
="vip_order"
 type
="string"
 indexed
="true"
 stored
="false"
 
/>
108         
<
field 
name
="kaipan_order"
 type
="sint"
 indexed
="true"
 stored
="false"
/>
109         
<
field 
name
="created"
 type
="sint"
 indexed
="true"
 stored
="false"
 
/>  
110        
<field name="latlng" type="location" indexed="true" />
111
         <dynamicField name="*_d" type="double" indexed="true" stored="true"/>
112     
</
fields
>
113 
114     
<
uniqueKey
>loupan_id
</
uniqueKey
>
115     
<
defaultSearchField
>search_kw
</
defaultSearchField
>
116     
<
solrQueryParser 
defaultOperator
="AND"
/>
117 
</
schema
>

 

在提交数据时的格式为:(纬度,经度:以字符串的方式提交给solr)

45.17614,-93.87341
40.7143,-74.006
37.7752,-122.4232

 

 例如要查寻距离纬度经度(31.254982,121.47501)5km的所有满足条件的楼盘:

 

http://192.168.181.140:8487/solr/loupan/select/?q=city_id:11&fq={!geofilt pt=31.254982,121.47501 sfield=latlng d=5}

查找满足指定距离的结果集,并按照距离由近到远排序

http://192.168.181.140:8487/solr/loupan/select/?q=*:*&fq={!geofilt}&pt=31.2367,121.501&sfield=latlng&d=5&sort=geodist()+asc

 

 

参考:

 

 

 

 

 

 

转载地址:http://iyuwl.baihongyu.com/

你可能感兴趣的文章
MySQL一些常用SQL语句
查看>>
深入理解Python中的ThreadLocal变量(上)
查看>>
JavaScript初应用:找到数组中出现最多的字母并给出个数以及每一个所在的位置...
查看>>
pjax不再神秘,hash、state那点事
查看>>
javascript创建对象方式
查看>>
mysql 配置优化
查看>>
【译】SVM零基础系列教程(一)
查看>>
[新手开源] 爬取韩寒“一个”文章且自动邮件发送功能
查看>>
【easeljs】显示位图 Bitmap 类
查看>>
pkg-config 学习笔记
查看>>
程序员,你有多久没关爱自己了?
查看>>
[CS101] Common Sorting Algorithms 常见排序算法
查看>>
【大数据】阿里巴巴的大规模数据流处理系统
查看>>
Centos-Kafka 消息队列
查看>>
蚂蚁金服微服务实践 | 开源中国年终盛典分享实录 ...
查看>>
你应该知道的 HBase 基础,都在这儿了
查看>>
理解RESTful架构
查看>>
详解docker中容器devicemapper设备的挂载流程
查看>>
head first python 6 class 扩展
查看>>
大数据,多大算“大
查看>>