小区周边配套(facilities)切换高德POI数据源并优化性能
- searchNearbyPoi改查ES高德POI(didata_map_poi_2024),按secondary_type中类过滤 - POI类型映射兼容高德分类:small_type精确匹配+secondary_type中类兜底 - 新增排除集合AROUND_EXCLUDE_TYPES:过滤ATM/培训机构/诊所/泛中餐厅/快餐厅等噪音类型 - 高德GCJ-02坐标转百度BD-09输出,经纬度保留6位小数 - 性能优化:批量12小区ES查询并行化、ES结果加缓存(MIDDLE)、ES客户端连接池单例复用、geo_distance只放filter - BaiduPlacePoi实现Serializable支持缓存序列化 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.fangjia.dal.mongo.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -12,7 +13,7 @@ import com.fangjia.dal.MongoEntity;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fangjia_base.baidu_place_poi")
|
||||
public class BaiduPlacePoi implements MongoEntity {
|
||||
public class BaiduPlacePoi implements MongoEntity, Serializable {
|
||||
private static final long serialVersionUID = 1840436549012703563L;
|
||||
private String id;
|
||||
private String city;//城市
|
||||
|
||||
+230
-22
@@ -13,6 +13,11 @@ import java.nio.charset.Charset;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -348,13 +353,166 @@ public class PropertyController {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 不适合做配套展示的POI类型(优先级高于AROUND_KEYWORD_FACTOR_NEW匹配,小类/中类命中任一即排除)
|
||||
*/
|
||||
private static final Set<String> AROUND_EXCLUDE_TYPES = new HashSet<String>() {
|
||||
{
|
||||
// 学校类:高等院校/职校/成人教育/培训机构/学校内部设施
|
||||
add("高等院校");
|
||||
add("职业技术学校");
|
||||
add("成人教育");
|
||||
add("培训机构");
|
||||
add("学校内部设施");
|
||||
// 医疗类:诊所/卫生院/疗养院/口腔医院/整形美容
|
||||
add("诊所");
|
||||
add("卫生院");
|
||||
add("疗养院");
|
||||
add("口腔医院");
|
||||
add("整形美容");
|
||||
// 银行类:ATM及自助银行(仅展示银行网点)
|
||||
add("自动提款机");
|
||||
add("银行相关");
|
||||
// 交通类:机场出发/到达口及直升机场(仅展示飞机场),公交车站(公交数据来自busStationService),货运设施
|
||||
add("机场出发/到达");
|
||||
add("直升机场");
|
||||
add("公交车站相关");
|
||||
add("货运火车站");
|
||||
add("货运港口码头");
|
||||
// 餐饮类:茶艺馆/冷饮店/糕饼店/甜品店/餐饮相关(泛称,POI名多为店名无意义)
|
||||
add("茶艺馆");
|
||||
add("冷饮店");
|
||||
add("糕饼店");
|
||||
add("甜品店");
|
||||
add("餐饮相关场所");
|
||||
add("餐饮相关");
|
||||
// 餐饮类:泛中餐厅/快餐厅/休闲餐饮场所(高德把无法细分的小餐馆全归此类,噪音主力),老字号
|
||||
add("中餐厅");
|
||||
add("快餐厅");
|
||||
add("休闲餐饮场所");
|
||||
add("老字号");
|
||||
// 酒店类:经济型连锁酒店/旅馆招待所/青年旅舍/住宿服务相关(低质POI多)
|
||||
add("经济型连锁酒店");
|
||||
add("旅馆招待所");
|
||||
add("青年旅舍");
|
||||
add("住宿服务相关");
|
||||
// 健身类:游泳馆/运动场所/户外健身场所(仅保留健身中心/综合体育馆)
|
||||
add("游泳馆");
|
||||
add("运动场所");
|
||||
add("户外健身场所");
|
||||
// 购物类:小商品市场及菜市场经济类(农副/蔬菜/果品/水产/花鸟等,超市分类仅展示现代商超)
|
||||
add("小商品市场");
|
||||
add("农副产品市场");
|
||||
add("蔬菜市场");
|
||||
add("果品市场");
|
||||
add("水产海鲜市场");
|
||||
add("花鸟鱼虫市场");
|
||||
add("花卉市场");
|
||||
add("宠物市场");
|
||||
add("旧货市场");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* POI类型 -> 配套分类(英文key)映射。
|
||||
* 通用类型兼容百度POI keyword; 高德POI优先按small_type精确匹配,未命中再按secondary_type中类匹配。
|
||||
*/
|
||||
private static final Map<String, String> AROUND_KEYWORD_FACTOR_NEW = new HashMap<String, String>() {
|
||||
{
|
||||
// ===== 高德POI secondary_type(中类) =====
|
||||
// 学校(中小学及幼儿园,高等院校/职业技术学校/成人教育/培训机构等见排除表)
|
||||
put("学校", "school");
|
||||
put("医院", "hospital");
|
||||
// 医疗(综合医院/三级甲等医院及眼科/骨科等专科,诊所/卫生院/口腔/整形等见排除表)
|
||||
put("综合医院", "hospital");
|
||||
put("专科医院", "hospital");
|
||||
// 银行(仅银行网点中类,ATM/银行相关见排除表)
|
||||
put("银行", "bank");
|
||||
put("超市", "supermarket");
|
||||
// 超市/商场
|
||||
put("超级市场", "supermarket");
|
||||
put("商场", "market");
|
||||
put("便民商店/便利店", "supermarket");
|
||||
put("综合市场", "market");
|
||||
// 美容美发
|
||||
put("美容美发店", "beautySalon");
|
||||
// 健身/运动
|
||||
put("运动场馆", "gym");
|
||||
// 公园
|
||||
put("公园广场", "park");
|
||||
// 交通
|
||||
put("机场相关", "airport");
|
||||
put("火车站", "trainStation");
|
||||
put("长途汽车站", "trainStation");
|
||||
put("港口码头", "dock");
|
||||
// 餐饮(仅保留有品类辨识度的:外国餐厅中类/咖啡厅中类;泛称类中餐厅/快餐厅/休闲餐饮场所等见排除表)
|
||||
put("外国餐厅", "restaurant");
|
||||
put("咖啡厅", "restaurant");
|
||||
// 酒店(旅馆招待所/住宿服务相关/经济型连锁酒店等见排除表)
|
||||
put("宾馆酒店", "hotel");
|
||||
|
||||
// ===== 高德POI small_type(小类)精确补充 =====
|
||||
// 学校
|
||||
put("小学", "school");
|
||||
put("中学", "school");
|
||||
put("幼儿园", "school");
|
||||
// 医疗(不含药房/医药保健销售/宠物医疗/口腔/整形)
|
||||
put("三级甲等医院", "hospital");
|
||||
// 超市/商场(超市小类由超级市场中类覆盖,小商品市场等见排除表)
|
||||
put("购物中心", "supermarket");
|
||||
put("普通商场", "market");
|
||||
// 健身/运动(游泳馆/运动场所/户外健身场所等见排除表)
|
||||
put("健身中心", "gym");
|
||||
put("综合体育馆", "gym");
|
||||
// 公园
|
||||
put("公园", "park");
|
||||
put("公园广场", "park");
|
||||
put("城市广场", "park");
|
||||
// 交通(货运火车站/货运港口码头见排除表)
|
||||
put("地铁站", "metro");
|
||||
put("火车站", "trainStation");
|
||||
put("长途汽车站", "trainStation");
|
||||
put("港口码头", "dock");
|
||||
put("客运港", "dock");
|
||||
put("飞机场", "airport");
|
||||
// 餐饮(仅保留有品类辨识度的小类:菜系/火锅/酒楼/料理等)
|
||||
put("综合酒楼", "restaurant");
|
||||
put("火锅店", "restaurant");
|
||||
put("特色/地方风味餐厅", "restaurant");
|
||||
put("四川菜(川菜)", "restaurant");
|
||||
put("湖南菜(湘菜)", "restaurant");
|
||||
put("广东菜(粤菜)", "restaurant");
|
||||
put("东北菜", "restaurant");
|
||||
put("安徽菜(徽菜)", "restaurant");
|
||||
put("福建菜", "restaurant");
|
||||
put("浙江菜", "restaurant");
|
||||
put("江苏菜", "restaurant");
|
||||
put("上海菜", "restaurant");
|
||||
put("北京菜", "restaurant");
|
||||
put("湖北菜(鄂菜)", "restaurant");
|
||||
put("云贵菜", "restaurant");
|
||||
put("西北菜", "restaurant");
|
||||
put("台湾菜", "restaurant");
|
||||
put("潮州菜", "restaurant");
|
||||
put("山东菜(鲁菜)", "restaurant");
|
||||
put("清真菜馆", "restaurant");
|
||||
put("海鲜酒楼", "restaurant");
|
||||
put("中式素菜馆", "restaurant");
|
||||
put("日本料理", "restaurant");
|
||||
put("韩国料理", "restaurant");
|
||||
put("外国餐厅", "restaurant");
|
||||
put("西餐厅(综合风味)", "restaurant");
|
||||
put("茶餐厅", "restaurant");
|
||||
put("咖啡厅", "restaurant");
|
||||
put("星巴克咖啡", "restaurant");
|
||||
put("上岛咖啡", "restaurant");
|
||||
// 酒店(经济型连锁酒店/旅馆招待所/青年旅舍等见排除表)
|
||||
put("宾馆酒店", "hotel");
|
||||
put("三星级宾馆", "hotel");
|
||||
put("四星级宾馆", "hotel");
|
||||
put("五星级宾馆", "hotel");
|
||||
put("奢华酒店", "hotel");
|
||||
|
||||
// ===== 百度POI keyword(兼容旧数据) =====
|
||||
put("医院", "hospital");
|
||||
put("美容院", "beautySalon");
|
||||
put("健身中心", "gym");
|
||||
put("公园/绿地", "park");
|
||||
@@ -362,12 +520,12 @@ public class PropertyController {
|
||||
put("公交", "bus");
|
||||
put("码头", "dock");
|
||||
put("机场", "airport");
|
||||
put("火车站", "trainStation");
|
||||
put("餐馆", "restaurant");
|
||||
put("酒店", "hotel");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Map<String, String> listKeyMap = new HashMap<String, String>() {
|
||||
{
|
||||
put("school", "schools");
|
||||
@@ -3402,6 +3560,7 @@ public class PropertyController {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("查询半径(radius)非法"));
|
||||
return mav;
|
||||
}
|
||||
final double radiusFinal = radius;
|
||||
Integer maxNum = getNum(jo);
|
||||
if (maxNum == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("最大记录数(num)非法"));
|
||||
@@ -3415,6 +3574,9 @@ public class PropertyController {
|
||||
|
||||
JSONArray jsonArray = new JSONArray();// 结果集
|
||||
boolean hasData = false;
|
||||
// 先解析参数并定位小区,再并行查询周边数据(ES查询是主要耗时点)
|
||||
List<District> districts = new ArrayList<District>(ja.size());
|
||||
final List<JSONObject> subJos = new ArrayList<JSONObject>(ja.size());
|
||||
for (Object o : ja) {
|
||||
JSONObject subJo = (JSONObject) o;
|
||||
String id = subJo.containsKey("id") ? subJo.getString("id") : null;
|
||||
@@ -3432,6 +3594,43 @@ public class PropertyController {
|
||||
}
|
||||
district = districtService.findByNameAndAlias(city, region, name, "district");
|
||||
}
|
||||
subJos.add(subJo);
|
||||
districts.add(district);
|
||||
}
|
||||
|
||||
// 并行查ES周边POI(每个小区一个任务)
|
||||
Map<District, List<BaiduPlacePoi>> poiMap = new HashMap<District, List<BaiduPlacePoi>>(districts.size());
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Math.min(districts.size(), 6));
|
||||
try {
|
||||
List<Future<List<BaiduPlacePoi>>> futures = new ArrayList<Future<List<BaiduPlacePoi>>>(districts.size());
|
||||
for (final District district : districts) {
|
||||
futures.add(executor.submit(new Callable<List<BaiduPlacePoi>>() {
|
||||
@Override
|
||||
public List<BaiduPlacePoi> call() {
|
||||
if (null == district || district.getLat2() == null || district.getLat2() == 0) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return baiduApiService.searchNearbyLocalDatabase(district, radiusFinal);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
try {
|
||||
poiMap.put(districts.get(i), futures.get(i).get(60, TimeUnit.SECONDS));
|
||||
} catch (Exception e) {
|
||||
poiMap.put(districts.get(i), null);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < districts.size(); idx++) {
|
||||
District district = districts.get(idx);
|
||||
JSONObject aroundJo = new JSONObject();
|
||||
if (null == district || district.getLat2() == null || district.getLat2() == 0) {
|
||||
jsonArray.add(aroundJo);
|
||||
@@ -3446,32 +3645,41 @@ public class PropertyController {
|
||||
double lat = district.getLat2() / 10000000000d;
|
||||
double lng = district.getLng2() / 10000000000d;
|
||||
|
||||
// 查询小区周边(所有类型)
|
||||
List<BaiduPlacePoi> arrs = baiduApiService.searchNearbyLocalDatabase(district, radius);
|
||||
// 查询小区周边(所有类型,已在上面并行预取)
|
||||
List<BaiduPlacePoi> arrs = poiMap.get(district);
|
||||
Map<String, List<AroundDto>> districtAroundMap = Maps.newHashMap();
|
||||
Map<String, Integer> districtAroundCountMap = Maps.newHashMap();
|
||||
|
||||
for (String key : AROUND_KEYWORD_FACTOR_NEW.keySet()) {
|
||||
districtAroundMap.put(AROUND_KEYWORD_FACTOR_NEW.get(key), new ArrayList<AroundDto>());// 把key的英文put到map并把value设置为一个List<AroundDto>引用
|
||||
}
|
||||
for (int i = 0; i < arrs.size(); i++) {
|
||||
BaiduPlacePoi poiObj = arrs.get(i);
|
||||
String _name = poiObj.getName();
|
||||
String keyword = poiObj.getKeyword();
|
||||
double latjs = poiObj.getLat();
|
||||
double lngjs = poiObj.getLng();
|
||||
String key = AROUND_KEYWORD_FACTOR_NEW.get(keyword);
|
||||
if (StringUtils.isBlank(key)) {
|
||||
continue;
|
||||
}
|
||||
if (arrs != null) {
|
||||
for (int i = 0; i < arrs.size(); i++) {
|
||||
BaiduPlacePoi poiObj = arrs.get(i);
|
||||
String _name = poiObj.getName();
|
||||
String keyword = poiObj.getKeyword();
|
||||
double latjs = poiObj.getLat();
|
||||
double lngjs = poiObj.getLng();
|
||||
// 高德POI: keyword存small_type(小类),streetId存secondary_type(中类)兜底
|
||||
if (AROUND_EXCLUDE_TYPES.contains(keyword) || AROUND_EXCLUDE_TYPES.contains(poiObj.getStreetId())) {
|
||||
continue;
|
||||
}
|
||||
String key = AROUND_KEYWORD_FACTOR_NEW.get(keyword);
|
||||
if (StringUtils.isBlank(key) && StringUtils.isNotBlank(poiObj.getStreetId())) {
|
||||
key = AROUND_KEYWORD_FACTOR_NEW.get(poiObj.getStreetId());
|
||||
}
|
||||
if (StringUtils.isBlank(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AroundDto dto = new AroundDto();
|
||||
dto.setName(_name);
|
||||
dto.setLat(latjs);
|
||||
dto.setLng(lngjs);
|
||||
dto.setDistance((int) GeoUtils.calculateDistance(lng, lat, lngjs, latjs));
|
||||
if (districtAroundMap.get(key) != null) {
|
||||
districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度
|
||||
AroundDto dto = new AroundDto();
|
||||
dto.setName(_name);
|
||||
dto.setLat(latjs);
|
||||
dto.setLng(lngjs);
|
||||
dto.setDistance((int) GeoUtils.calculateDistance(lng, lat, lngjs, latjs));
|
||||
if (districtAroundMap.get(key) != null) {
|
||||
districtAroundMap.get(key).add(dto);// 按key值取出list add 周边名称已经经纬度
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+146
-6
@@ -1,12 +1,17 @@
|
||||
package com.fangjia.service.api;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.fangjia.core.ProvinceData;
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.*;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.mongo.dao.BaiDuSearchCacheDao;
|
||||
@@ -19,6 +24,7 @@ import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONException;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@@ -91,14 +97,148 @@ public class BaiduApiServiceImpl extends AbstractHttpApiService implements Baidu
|
||||
@Override
|
||||
public List<BaiduPlacePoi> searchNearbyLocalDatabase(District district,
|
||||
double radius) {
|
||||
if(district.getCity() == null ||district.getLat2() == null || district.getLng2() == null){
|
||||
return null;
|
||||
}
|
||||
double lat = district.getLat2()/10000000000d;
|
||||
double lng = district.getLng2()/10000000000d;
|
||||
return searchNearbyLocalDatabase(district.getCity(), lat,lng,radius);
|
||||
if(district.getCity() == null || district.getLat() == null || district.getLng() == null){
|
||||
return null;
|
||||
}
|
||||
return searchNearbyPoi(district.getCity(), district.getLat()/10000000000d, district.getLng()/10000000000d, radius);
|
||||
}
|
||||
|
||||
/** ES查询客户端单例,复用连接池 */
|
||||
private static volatile HttpRequest esHttpRequest;
|
||||
|
||||
private static HttpRequest getEsHttpRequest() {
|
||||
if (esHttpRequest == null) {
|
||||
synchronized (BaiduApiServiceImpl.class) {
|
||||
if (esHttpRequest == null) {
|
||||
esHttpRequest = new HttpRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
return esHttpRequest;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<BaiduPlacePoi> searchNearbyPoi(final String city ,final double lat,final double lng, final double radius) {
|
||||
|
||||
String cacheKey = city + "_" + lat + "_" + lng + "_" + radius;
|
||||
Object cached = CacheUtils.getValue(this.getClass(), cacheKey);
|
||||
if (cached != null) {
|
||||
return (List<BaiduPlacePoi>) cached;
|
||||
}
|
||||
|
||||
Map<String,String> header = new HashMap<String, String>();
|
||||
try {
|
||||
String auth = "Basic " + Base64.encodeBase64String("elastic:elasticsearch".getBytes("UTF-8"));
|
||||
header.put("Authorization", auth);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String seawaterUrl = "http://192.168.0.89:9200/didata_map_poi_2024/_search";
|
||||
JSONObject root = new JSONObject();
|
||||
// _source 过滤
|
||||
JSONArray includes = new JSONArray();
|
||||
includes.add("small_type");
|
||||
includes.add("secondary_type");
|
||||
includes.add("address");
|
||||
includes.add("data_id");
|
||||
includes.add("name");
|
||||
includes.add("location");
|
||||
JSONObject sourceFilter = new JSONObject();
|
||||
sourceFilter.put("includes", includes);
|
||||
root.put("_source", sourceFilter);
|
||||
// bool 查询
|
||||
JSONObject bool = new JSONObject();
|
||||
JSONArray mustArray = new JSONArray();
|
||||
// term status
|
||||
JSONObject termStatus = new JSONObject();
|
||||
termStatus.put("status", "0");
|
||||
JSONObject termWrapper = new JSONObject();
|
||||
termWrapper.put("term", termStatus);
|
||||
mustArray.add(termWrapper);
|
||||
// city status
|
||||
JSONObject termCity = new JSONObject();
|
||||
termCity.put("city", city + "市");
|
||||
JSONObject cityTermWrapper = new JSONObject();
|
||||
cityTermWrapper.put("term", termCity);
|
||||
mustArray.add(cityTermWrapper);
|
||||
// 按高德POI中类(secondary_type)过滤,覆盖菜系等细分小类
|
||||
JSONObject termType = new JSONObject();
|
||||
termType.put("secondary_type", Arrays.asList(
|
||||
"学校", "综合医院", "专科医院",// 学校/医疗
|
||||
"银行",// 银行(仅网点,ATM/银行相关不展示)
|
||||
"超级市场", "商场", "便民商店/便利店", "综合市场",// 超市/商场
|
||||
"美容美发店",// 美容美发
|
||||
"运动场馆",// 健身/运动
|
||||
"公园广场",// 公园
|
||||
"机场相关", "火车站", "长途汽车站", "港口码头",// 交通
|
||||
"外国餐厅", "咖啡厅",// 餐饮(仅品类辨识度高的中类,泛中餐厅/快餐厅等小类噪音多由小类精确映射过滤)
|
||||
"宾馆酒店"));// 酒店(仅宾馆酒店中类)
|
||||
JSONObject typeTermWrapper = new JSONObject();
|
||||
typeTermWrapper.put("terms", termType);
|
||||
mustArray.add(typeTermWrapper);
|
||||
bool.put("must", mustArray);
|
||||
// geo_distance 只放在filter(不评分,走filter cache,勿重复放must)
|
||||
JSONObject point = new JSONObject();
|
||||
point.put("lat", lat);
|
||||
point.put("lon", lng);
|
||||
JSONObject geoDistance = new JSONObject();
|
||||
geoDistance.put("distance", radius + "m");
|
||||
geoDistance.put("location", point); // 直接放入对象
|
||||
JSONObject geoWrapper = new JSONObject();
|
||||
geoWrapper.put("geo_distance", geoDistance);
|
||||
JSONArray filterArray = new JSONArray();
|
||||
filterArray.add(geoWrapper);
|
||||
bool.put("filter", filterArray);
|
||||
JSONObject query = new JSONObject();
|
||||
query.put("bool", bool);
|
||||
root.put("query", query);
|
||||
root.put("size", "300");
|
||||
// ---------- 按距离排序 ----------
|
||||
JSONArray sortArray = new JSONArray();
|
||||
JSONObject geoDistanceSort = new JSONObject();
|
||||
// 指定坐标点(对象格式)
|
||||
geoDistanceSort.put("location", point);
|
||||
// 排序参数(与 location 平级)
|
||||
geoDistanceSort.put("order", "asc");
|
||||
geoDistanceSort.put("unit", "m"); // 单位:米
|
||||
JSONObject sortWrapper = new JSONObject();
|
||||
sortWrapper.put("_geo_distance", geoDistanceSort);
|
||||
sortArray.add(sortWrapper);
|
||||
root.put("sort", sortArray);
|
||||
try {
|
||||
String res = getEsHttpRequest().postWithBody(seawaterUrl, root, header, "UTF-8");
|
||||
JSONObject json = JSONObject.fromObject(res);
|
||||
ArrayList<BaiduPlacePoi> lists = new ArrayList<BaiduPlacePoi>();
|
||||
if(json.has("hits") && json.getJSONObject("hits").has("hits")){
|
||||
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||
for(int i = 0; i < hits.size(); i++){
|
||||
JSONObject hit = hits.getJSONObject(i);
|
||||
JSONObject source = hit.getJSONObject("_source");
|
||||
JSONObject location = source.getJSONObject("location");
|
||||
BaiduPlacePoi poi = new BaiduPlacePoi();
|
||||
poi.setId(source.getString("data_id"));
|
||||
poi.setName(source.getString("name"));
|
||||
poi.setAddress(source.optString("address"));
|
||||
poi.setKeyword(source.optString("small_type"));
|
||||
// 中类存入streetId,供上层做类型兜底匹配
|
||||
poi.setStreetId(source.optString("secondary_type"));
|
||||
poi.setCity(city);
|
||||
// 高德坐标(GCJ-02)转百度坐标(BD-09),经纬度保留6位小数
|
||||
Map<String, Double> bdLocation = GeoUtils.gcj02ToBd09(location.getDouble("lat"), location.getDouble("lon"));
|
||||
poi.setLat(DataUtil.roundDouble(bdLocation.get(GeoUtils.LAT), 6));
|
||||
poi.setLng(DataUtil.roundDouble(bdLocation.get(GeoUtils.LNG), 6));
|
||||
poi.setStatus(0);
|
||||
lists.add(poi);
|
||||
}
|
||||
}
|
||||
CacheUtils.putValueCompress(CachePolicyEnum.MIDDLE, this.getClass(), cacheKey, lists);
|
||||
return lists;
|
||||
} catch (HttpRequestException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, JSONObject> searchNearBy(List<String> keywords, double lat, double lng, double radius, String ak){
|
||||
List<QueryParam> paramList = new ArrayList<QueryParam>();
|
||||
paramList.add(new QueryParam("lat",lat));
|
||||
|
||||
Reference in New Issue
Block a user