通过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. tensorflow softmax_cross_entropy_with_logits函数

    1.softmax_cross_entropy_with_logits tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=Non ...

  2. 将Asp.Net Core和corefx移植到.Net 4.0

    引言 因为工作内容的原因需要兼容 XP,而 XP 最多支持到.Net Framework 4.0.因此无法享受到 .Net Core 带来的一堆很好用的库,好在无论 corefx 还是 Asp.Net ...

  3. 小白也能看懂的插件化DroidPlugin原理(三)-- 如何拦截startActivity方法

    前言:在前两篇文章中分别介绍了动态代理.反射机制和Hook机制,如果对这些还不太了解的童鞋建议先去参考一下前两篇文章.经过了前面两篇文章的铺垫,终于可以玩点真刀实弹的了,本篇将会通过 Hook 掉 s ...

  4. iOS-联系人应用(一)

    环境:xcode6,iphone 4s simulator with iOS8.0 一.功能界面介绍 1.1 应用启动进入联系人列表页面,数据为模拟数据,来源与一个plist文件: 1.2 点击右上角 ...

  5. css的选择器的优先级

    css覆盖是在打代码的时候,开发者很普通很普通,也是很经常经常用到的,但是容易混淆他们之间的优先级. [][][] 第一个是id,第二个是class,第三个是元素名.有一个就加一.比较这个三位数的大小 ...

  6. HTML <img>标签 创建图像映射

    初级前端一枚 下面代码是在图片上创建图像映射 自己整理了下 做个笔记 希望也可以帮助后来学习的朋友! <map name="planetmap"> <area s ...

  7. MySQL 6.0安装图解

    MySQL 6.0安装图解 由于免费,MySQL数据库在项目中用的越来越广泛,而且它的安全性能也特别高,不亚于oracle这样的大型数据库软件.可以简单的说,在一些中小型的项目中,使用MySQL ,P ...

  8. Linq to Objects for Java 发布 1.0.1 版本

    现在 java 支持 linq 啦.比原生 stream api 更好用,功能更强大.现已发布 version 1.0.1 地址: https://github.com/timandy/linq. A ...

  9. windows 快捷方式(.lnk)代码执行漏洞(CVE-2017-8464 )[附EXP生成工具]

    最近看到网上曝光了一个windows远程代码执行的漏洞,黑客可以通过一个快捷方式在用户电脑上执行任意指令,于是便对该漏洞进行了部分分析. 1. 漏洞描述: MicrosoftWindows .LNK  ...

  10. js的call,apply,bind的使用与区别

    在原生js中会有三个很常见的函数,call,apply,bind 他们的作用就是改变当前函数的this指针, 但是细微来说他们还是有不同的. 1)call,apply都是执行某一函数,发现this有变 ...