通过solr的domain-import,将mysql的数据通过查询,导入到solr中。java通过使用solrj,链接solr,调用domaininport,并将分页参数设置到domain-import中(防止查询所有数据),通过线程sleep,查询solr导入情况,如果导入成功,则继续导入下一页,直到所有数据导入完成。数据导入完成之后,客户端通过地图的缩放等级,发送当前位置的精度纬度,以及当前地图显示的最大距离,将数据发送值服务器,服务器通过查询solr中数据,将对应数据所在的经纬度、统计等信息返回给客户端。

solr chema配置

<fieldtype name="geohash" class="solr.GeoHashField"/>
从数据导入solr配置
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.211.226:3306/adwl_dev_v2?useUnicode=true&amp;characterEncoding=utf8"
user="root"
password="111111" />
<document>
<entity name="solr_docking_insert" transformer="DateFormatTransformer"
query=" sql查询*** limit ${dataimporter.request.startpage},${dataimporter.request.endpage}"> </entity>
</document>
</dataConfig>
//动态调用SolrDomainImport
public static String importData(Long start,String url){
System.out.println("货源导入数据开始:"+start+" "+perPage);
Map<String , String> map=new HashMap<String, String>();
if(isclear){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
isclear=false;
map.put("clean", "true");
}else{
map.put("clean", "false");
}
map.put("command", "full-import");
map.put("commit", "true");
map.put("debug", "false");
map.put("endpage", perPage+"");
map.put("indent", "true");
map.put("optimize", "false");
map.put("startpage", start+"");
map.put("verbose", "false");
map.put("wt", "json");
//向移动交互服务发送httppost请求
String str= HttpPostUtil.doPost(url, map,null);
return str;
}
    public SimpleResult groupCargo(LbsSearchRequestDto lbsSearchRequestDto){
try{
if(lbsSearchRequestDto==null)
return new SimpleResult("body不能为空", StateCode.VALIDATOR_FAIL, null, false);
LbsSearchBodyDto lbsBdoy=lbsSearchRequestDto.getBodyDto();
if(lbsBdoy.getLevel()==null)
return new SimpleResult("Level不能为空", StateCode.VALIDATOR_FAIL, null, false);
List<String> fl=new ArrayList<String>();
//level为省级按照省分组
if(lbsBdoy.getLevel()==1){
fl.add("rciShipperCity:notfind");
fl.add("rciShipperArea:notfind");
//level为市级按照市分组
}else if(lbsBdoy.getLevel()==2){
fl.add("rciShipperArea:notfind");
fl.add("-rciShipperCity:notfind");
//level为区县级按照区县分组
}else if(lbsBdoy.getLevel()==3){
fl.add("-rciShipperArea:notfind");
}
if(lbsBdoy.getPageSize()==null)lbsBdoy.setPageSize(0);
if(lbsBdoy.getPageNumber()==null)lbsBdoy.setPageNumber(50);
//按照经纬度和距离查询
PageData data=solrCargoLLSearch.queryLL(lbsBdoy.getPageSize(), lbsBdoy.getPageNumber(), lbsBdoy.getD(), "geohash", lbsBdoy.getLat(),lbsBdoy.getLon(), fl); LbsSearchGroupResponseDto lsgrb=new LbsSearchGroupResponseDto();
LbsSearchGroupResponseBodyDto lsgrbd=new LbsSearchGroupResponseBodyDto();
lsgrb.setBodyDto(lsgrbd);
List<LbsGroupMsg> lbsGroupMsgs=new ArrayList<LbsGroupMsg>();
String solrMsg=data.getData();
JSONArray array=JSONArray.parseArray(solrMsg);
for(int i=0;i<array.size();i++){
//TODO数据整合
}
lsgrbd.setLbsGroupMsgs(lbsGroupMsgs);
return new SimpleResult("成功", 200, lsgrbd, true);
}catch(Exception e){
e.printStackTrace();
return new SimpleResult("服务器错误", 500, null, true);
} }
/**
*
* @param orderField 排序字段 必须为index字段
* @param start 分页开始值
* @param rows 分页结束值
* @param filters 条件
* @return
*/
public PageData queryDataArrays(String orderField,Integer start,Integer rows,Map<String, String>latAndlon,List<String>filters){
PageData pageData=null;
//HttpSolrServer server = SolrServerFactory.getCargoServer();
SolrQuery query = new SolrQuery(q);
query.setStart(start);
query.setRows(rows);
if(null!=latAndlon){
query.addFilterQuery("{!geofilt}");
Set<String>set=latAndlon.keySet();
for(String key:set){
System.out.println(key+" : "+latAndlon.get(key));
query.set(key, latAndlon.get(key));
}
}
if(filters!=null)
for(String filter:filters)
query.addFilterQuery(filter); if(orderField!=null)
query.addSort(orderField, ORDER.desc);
try {
QueryResponse rsp = getServer().query(query);
SolrDocumentList docs = rsp.getResults();
pageData=new PageData();
pageData.setSize(docs.getNumFound());
pageData.setData(getJsons(docs));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pageData;
}

solr-geohsah 按照距离搜索分组的更多相关文章

  1. 使用 Apache Lucene 和 Solr 4 实现下一代搜索和分析

    使用 Apache Lucene 和 Solr 4 实现下一代搜索和分析 使用搜索引擎计数构建快速.高效和可扩展的数据驱动应用程序 Apache Lucene™ 和 Solr™ 是强大的开源搜索技术, ...

  2. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第八天】(solr服务器搭建、搜索功能实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  3. solr多词匹配搜索问题及解决

    使用solr进行某较长词搜索时出现了一些问题,及解决方案. 1.问题:solr默认使用OR方式搜索,当搜索一个很长的次,比如“XX集团股份有限公司”,分词器分词后,使用OR方式匹配,会匹配到很多结果. ...

  4. Lucene全文搜索 分组,精确查找,模糊查找

    http://zm603380946.iteye.com/blog/1827318 完全个人理解,如有更好的方法,欢迎一起讨论 LuceneUtils.java package com.zbiti.l ...

  5. 利用solr实现商品的搜索功能

      后期补充: 为什么要用solr服务,为什么要用luncence? 问题提出:当我们访问购物网站的时候,我们可以根据我们随意所想的内容输入关键字就可以查询出相关的内容,这是怎么做到呢?这些随意的数据 ...

  6. Solr的精确匹配搜索

    情景: 利用Solr做一批词的逆文档频率.Solr中存储的每条数据为一篇文章,此时需要查出某词在多少篇文章中出现过,然后用公式:某词逆文档频率 = 总文章数 / (出现过某词的文章数+1) 来计算. ...

  7. solr通过http请求搜索

    请求搜索必要的条件是:设置搜索条件params 设置 1.简单条件 SolrParams params = new SolrQuery("name:小飞鸟 AND  id:1520" ...

  8. solr安装部署、solr测试创建core、用solrj 访问solr(索引和搜索)

    一.安装solr4.8: 1.把apache-solr-4.8.1\example\webapps下的solr.war文件拷贝到Tomcat下的Tomcat7.0\webapps目录下,tomcat启 ...

  9. Sphinx的GEO距离搜索 [转载]

    近项目用sphinx做地理搜索,可是结果总是不对,明明很近却搜不到 结果检查sphinx源文件: static inline double sphSqr ( double v ) { return v ...

随机推荐

  1. AngularJS $compile动态生成html

    angular.module('app') .directive('compile', function ($compile) { return function (scope, element, a ...

  2. [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]

    历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...

  3. .NET MVC与三层架构

    虽然接触了两者有一段时间了,但是有时还是会混淆概念,在此处不打算说明二者的区别,因为二者都是架构模式,并且也有一定的共存度,在实际开发中,严格区分意义不大.基于最近涉及到这部分知识就在复习下,编程过程 ...

  4. 【整理】01. Fiddler 杂记

    抓手机包步骤: Tools -- Fiddler Options -- Connections (默认)Fiddler listens on port:8888 (勾选)Allow remote co ...

  5. Windows10系统PHP开发环境配置

    Windows下搭建(Apache+PHP+MySQL)=>WAMP Linux下搭建(Apache+PHP+MySQL) =>LAMP PHP开发环境配置一般有套件安装和自定义安装两种方 ...

  6. Python网络数据采集4-POST提交与Cookie的处理

    Python网络数据采集4-POST提交与Cookie的处理 POST提交 之前访问页面都是用的get提交方式,有些网页需要登录才能访问,此时需要提交参数.虽然在一些网页,get方式也能提交参.比如h ...

  7. HDU6055 Regular polygon(计算几何)

    Description On a two-dimensional plane, give you n integer points. Your task is to figure out how ma ...

  8. cmd命令行进入DOS方式编译运行C语言程序实现字符串转换

    需求:输入一个字符串(长度小于50),然后过滤掉所有的非数字字符,得到由数字字符组成的字符串,将其转化为double型结果输出(4位小数). 源程序: #include<stdio.h>i ...

  9. overlay 如何实现跨主机通信?- 每天5分钟玩转 Docker 容器技术(52)

    上一节我们在 host1 中运行了容器 bbox1,今天将详细讨论 overlay 网络跨主机通信的原理. 在 host2 中运行容器 bbox2: bbox2 IP 为 10.0.0.3,可以直接 ...

  10. [ZYNQ-7]PS处理PL外部中断的简单实例的剖析 (参考米联miz702n)

    Zynq的ARM通过GIC中断控制器来接收核仲裁所有的中断.由于中断向量表只有4Bytes大小,仅仅正好存放一条跳转语句,因此当产生一个外部中断时,中断处理的大致过程:PC内容保存到LR_IRQ用于中 ...