• solr实现满足指定距离范围条件的搜索


    配置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)

    <field name="store">45.17614,-93.87341</field>  <!-- Buffalo store -->
    <field name="store">40.7143,-74.006</field>     <!-- NYC store -->
    <field name="store">37.7752,-122.4232</field>   <!-- San Francisco store -->

     例如要查寻距离纬度经度(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

    参考:

  • 相关阅读:
    Ubuntu18.04安装NAVIDIA驱动
    ubuntu 设置root用户密码并实现root用户登录
    配置ubuntu允许远程SSH连接
    Centos7安装yum命令
    NVDIA往期在线研讨会地址 论坛提问地址
    二进制安装单master节点测试环境k8s集群
    kubeadm初始化k8s-延长证书过期时间
    kubeadm初始化k8s-删除控制节点-重新把控制节点加入集群步骤
    kubeadm安装的多master节点的k8s高可用集群
    二进制安装多master节点的k8s集群
  • 原文地址:https://www.cnblogs.com/xiazh/p/2380283.html
Copyright © 2020-2023  润新知