List<StoreSearchVO> queryStoreVO;
SolrQuery query = new SolrQuery();
query.setStart((params.getPageNo() - 1) * params.getPageSize());
query.setRows(params.getPageSize());
//搜索词
Matcher m = numRegExp.matcher(params.getPoiName());
if (m.matches()) {
query.setQuery("storeName:(*" + params.getPoiName() + "*) OR storeId:(*" + params.getPoiName() + "*)");
} else {
query.setQuery("storeName:(" + params.getPoiName() + ")");
}
query.addFilterQuery("regions:" + params.getRegionCode());
query.addFilterQuery("{!geofilt}");
//当前经纬度
query.add("pt", params.getLatitude() + "," + params.getLongitude());
//就近 20 km 的所有数据
query.add("d", "20000");
//经纬度字段
query.add("sfield", "latLon");
//指定返回的列
query.addField("storeId,storeName,distance:geodist()");
query.addSort("score", SolrQuery.ORDER.desc);
query.addSort("geodist()", SolrQuery.ORDER.asc);
QueryResponse queryResponse = this.solrClient.query(query, SolrRequest.METHOD.POST);
SolrDocumentList documentList = queryResponse.getResults();
queryStoreVO = documentList.stream().map(document -> {
StoreSearchVO storeVO = new StoreSearchVO();
storeVO.setStoreId(document.getFieldValue("storeId") == null ? "" : document.getFieldValue("storeId").toString());
storeVO.setOrgName(document.getFieldValue("storeName") == null ? "" : document.getFieldValue("storeName").toString());
storeVO.setDistance(document.getFieldValue("distance") == null ? BigDecimal.ZERO : new BigDecimal(document.getFieldValue("distance").toString()));
return storeVO;
}).collect(Collectors.toList());