(转载)solr实现满足指定距离范围条件的搜索

配置schema.xml

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="aifang-loupan" version="1.1">
    <types>
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="integer" class="solr.IntField" omitNorms="true"/>

        <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>

        <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>

        <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="slong" class="solr.SortableLongField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="true"/>

        <fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/>
        <fieldtype name="ignored" stored="false" indexed="false" class="solr.StrField"/>
        <fieldtype name="location" class="solr.LatLonType" subFieldSuffix="_d"/>
        <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
              <analyzer type="index">
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
                <filter class="solr.LowerCaseFilterFactory"/>
              </analyzer>
              <analyzer type="query">
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
                <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
                <filter class="solr.LowerCaseFilterFactory"/>
              </analyzer>
        </fieldType>

    </types>

    <fields>
        <field name="loupan_id" type="integer" indexed="true" stored="true" required="true"/>
        <field name="city_id" type="integer" indexed="true" stored="false"/>
        <field name="loupan_name" type="text" indexed="true" stored="false"/>
        <field name="loupan_pinyin" type="string" indexed="true" stored="false"/>
        <field name="alias_name" type="text" indexed="true" stored="false"/>
        <field name="former_name" type="text" indexed="true" stored="false"/>
        <field name="region_title" type="text" indexed="true" stored="false" />
        <field name="region_id" type="int" indexed="true" stored="false"/>
        <field name="sub_region_title" type="text" indexed="true" stored="false"/>
        <field name="sub_region_id" type="int" indexed="true" stored="false"/>
        <field name="regions_string" type="string" indexed="true" stored="false" multiValued="true"/>
        <field name="address" type="text" indexed="true" stored="false"/>
        <field name="proxy_address" type="text" indexed="true" stored="false"/>
        <field name="chanquan" type="text" indexed="true" stored="false"/>
        <field name="build_type" type="text" indexed="true" stored="false" multiValued="true"/>
        <field name="property_type" type="text" indexed="true" stored="false" multiValued="true"/>
        <field name="fitment_type" type="text" indexed="true" stored="false" multiValued="true"/>
        <field name="search_kw" type="text" indexed="true" multiValued="true" stored="false" />
        <field name="investor" type="text" indexed="true" stored="false"/>
        <field name="company" type="text" indexed="true" stored="false"/>
        <field name="loop_line"   type="text"  indexed="true" stored="false" />
        <field name="status_sale" type="integer" indexed="true" stored="false"/>
        <field name="status_disp" type="integer" indexed="true" stored="false"/>
        <field name="search_sale" type="integer" indexed="true" stored="false" multiValued="true"/>
        <field name="jiaofang_date" type="sint" indexed="true" stored="false"/>
        <field name="kaipan_date" type="sint" indexed="true" stored="false"/>
        <field name="price" type="sint" index="true" stored="false"/>
        <field name="baidu_lat"   type="sfloat"  indexed="true" stored="false"/>
        <field name="baidu_lng"   type="sfloat"  indexed="true" stored="false"/>
        <field name="lat"  type="sfloat"  indexed="true"  stored="false"/>
        <field name="lng"  type="sfloat"  indexed="true"  stored="false"/>
        <field name="metro_subway_id"  type="integer" indexed="true"  stored="false" multiValued="true" />
        <field name="metro_station_id" type="integer" indexed="true"  stored="false" multiValued="true" />
        <field name="metro_enabled"    type="integer" indexed="true"  stored="false"/>
        <field name="metro_info"       type="text"  indexed="true" stored="false" multiValued="true" />
       <field name="loop_line_id" type="integer" indexed="true" stored="false"/>
       <field name="property_type_id" type="integer" indexed="true" stored="false" multiValued="true"/>
       <field name="build_type_id" type="integer" indexed="true" stored="false" multiValued="true"/>
       <field name="fitment_type_id" type="integer" indexed="true" stored="false" multiValued="true"/>
       <field name="developer_id" type="integer" indexed="true" stored="false" multiValued="true"/>
       <field name="developer_title" type="string" indexed="true" stored="false"/>
       <field name="business_id" type="integer" indexed="true" stored="false"/>
       <field name="business_title" type="string" indexed="true" stored="false"/>
       <field name="loupan_extend_type" type="sint" indexed="true" stored="false" multiValued="true"/>
        <field name="trip_fitment_style" type="text" indexed="true" stored="false" />
        <field name="trip_feature_recommend" type="text" indexed="true" stored="false" multiValued="true" />
        <field name="trip_spot" type="text" indexed="true" stored="false" multiValued="true" />
        <field name="trip_transport" type="text" indexed="true" stored="false" multiValued="true" />
        <field name="trip_scenic_region" type="text" indexed="true" stored="false" multiValued="true" />
        <field name="trip_property_service" type="text" indexed="true" stored="false" multiValued="true" />
        <field name="trip_scenic_spot" type="text" indexed="true" stored="false"/>
        <field name="trip_created" type="sint" indexed="true" stored="false" />
        <field name="is_trip" type="int" indexed="true" stored="false" />
        <field name="level" type="sint" indexed="true" stored="false"/>
        <field name="loupan_pv_day" type="sint" indexed="true" stored="false" />
        <field name="operator_ids" type="integer" indexed="true" stored="false" multiValued="true"/>
        <field name="operator_names" type="string" indexed="true" stored="false" multiValued="true"/>
        <dynamicField name="*_grade" type="sint" indexed="true" stored="false" />
        <field name="updated" type="sint" indexed="true" stored="false" />
        <field name="news_id" type="int" indexed="true" stored="false" />
        <field name="news_update" type="sint" indexed="true" stored="false" />
        <field name="rank" type="sfloat" indexed="true" stored="false" />
        <field name="sale_order" type="sint" indexed="true" stored="false" />
        <field name="vip_order" type="string" indexed="true" stored="false" />
        <field name="kaipan_order" type="sint" indexed="true" stored="false"/>
        <field name="created" type="sint" indexed="true" stored="false" />
        <field name="latlng" type="location" indexed="true" />
        <dynamicField name="*_d" type="double" indexed="true" stored="true"/>
    </fields>

    <uniqueKey>loupan_id</uniqueKey>
    <defaultSearchField>search_kw</defaultSearchField>
    <solrQueryParser defaultOperator="AND"/>
</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

参考:

http://wiki.apache.org/solr/SpatialSearchDev

http://wiki.apache.org/solr/SpatialSearch

(转载)solr实现满足指定距离范围条件的搜索

时间: 2024-07-29 21:30:06

(转载)solr实现满足指定距离范围条件的搜索的相关文章

CSS3实现的div元素水平运动指定距离

CSS3实现的div元素水平运动指定距离:本章节分享一段,它实现了利用CSS3让div元素水平运动一段距离.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</

【转载】Lucene.Net无障碍学习和使用:搜索篇

在上一篇中,我们初步理解了索引的增删改查基本操作.本文着重介绍一下常用的搜索,以及搜索结果的排序和分页.本文的搜索主要是基于前一篇介绍的文本文件的索引,建议下载最后改进的demo对照着看阅读本文,同时大家可以自己动手创建一些测试文本,然后建立索引并搜索试试看. 一.初步认识搜索 先从上一篇示例代码中我们摘录一段代码看看搜索的简单实现: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 private TopDocs Searc

在指定的盘符,搜索出给定后缀名的文件

# -*- coding: cp936 -*- #python 27 #xiaodeng #http://www.cnblogs.com/hongten/p/hongten_python_file_info.html #在指定的盘符,搜索出给定后缀名的文件 #本脚本知识点: #os.listdir():返回指定目录下的所有文件和目录名(文件夹) #os.path.getsize(name):获得文件大小,如果name是目录返回OL #os.path.join(path,name):连接目录与文件

比百度还好用的搜索功能,支持「多条件」搜索哟

在「发布搜素」时,超级表格新增了「多条件」搜索.改变了旧版只能单条件的搜索情况.本次搜索可以分为三个维度进行设置. ①允许模糊搜索  ②多行展示  ③必填 允许模糊搜素 不勾选则默认为「精确搜索」 搜索的内容必须与所选择的列范围中内容一字不差才能搜索到相应记录. 而勾选了「允许模糊搜索」 搜索的内容只要被包含于所选择的列范围中,就能搜索到相应记录. 多行展示 不勾选则默认为「单行展示」 无论选择多少列范围,都只有一个输入框供其搜索. 而勾选「多行展示」 你选择了多少的列,就会出现多少个输入框.可

利用Solr服务建立的界面化站内搜索---solr2

继上次匆匆搭建起结合solr和nutch的所谓站内搜索引擎之后,虽当时心中兴奋不已,可是看了看百度,再只能看看我的控制台的打印出每个索引项的几行文字,哦,好像差距还是有点大…… 简陋的信息显示环境最起码给了我一个信号,这条路没有走错,好吧,让我们来继续探索搜索引擎的奥秘吧. 上期回顾:上次主要是介绍了solrj,通过solrj的api与solr服务器进行通信,获取服务器上的索引数据以及在编写程序中遇到的一些问题和解决方法.本期主要是建立与solr服务器的通信,提供搜索界面输入关键字或搜索规则,根

lucene多条件查询”搜索—BooleanQuery

/** * "多条件查询"搜索-BooleanQuery * BooleanQuery也是实际开发过程中经常使用的一种Query. * 它其实是一个组合的Query,在使用时可以把各种Query对象添加进去并标明它们之间的逻辑关系. * 在本节中所讨论的所有查询类型都可以使用BooleanQuery综合起来. * BooleanQuery本身来讲是一个布尔子句的容器,它提供了专门的API方法往其中添加子句, * 并标明它们之间的关系,以下代码为BooleanQuery提供的用于添加子句

[转载] Solr使用入门指南

转载自http://blog.csdn.net/liuzhenwen/article/details/4060922 由于搜索引擎功能在门户社区中对提高用户体验有着重要的作用,在门户社区中涉及大量需要搜索引擎的功能需求,目前在实现搜索引擎的方案上有几种方案可供选择: 1. 基于Lucene自己进行封装实现站内搜索.工作量及扩展性都较大,不采用. 2. 调用Google.Baidu的API实现站内搜索.同第三方搜索引擎绑定太死,无法满足后期业务扩展需要,暂时不采用. 3. 基于Compass+Lu

NSPredicate类,指定过滤器的条件---董鑫

/* 比较和逻辑运算符 就像前面的例子中使用了==操作符,NSPredicate还支持>, >=, <, <=, !=, <>,还支持AND, OR, NOT(或写成C语言样式&&, ||, ! ),其中AND,OR,NOT还是不区分大小写的 */ NSArray *array = [NSArray array]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"age &

ArcGis基础——相接面制造指定距离的分隔带

回家,出发前夜,看完电影吃晚饭回到住处已近十一点,和同事扯了一会儿淡,正准备去睡觉,这哥们儿突然想起一个问题: 如何把相接的面搞出一个20cm的分隔带?因为两区划定项目数据质检要求不同的地块图斑间应有大于20cm的距离,而从其他数据转绘处理而来的地块图层面图斑是相接的,不同图斑种植年份不同所以不能进行合并. 他的打算线转面,然后找到图斑间的公共边,进行缓冲,然后对原图班进行擦除. 我反问他“如何确定图斑的公共边?”,一顿“批斗”. 他抛出这个问题的时候我便想到了找出图斑公共边的的方法以及整个流程