Authored by hugufei

Merge branch 'dev'

... ... @@ -86,11 +86,11 @@ BASE_BIN_DIR=`dirname $0`
export JAVA_HOME=/usr/local/java
export WEB_APP_HOME=/home/dev/yoho-search-service/deploy
export SERVER_PORT=8
export SERVER_PORT=7
export PRODUCTION_MODE="TEST"
export SERVER_HOME=/usr/local/tomcat
export SERVER_TYPE=tomcat
export SERVER_NAMESPACE=search-service
export SERVER_NAMESPACE=yohosearch
export GW_URL=$Gateway_URL
... ...
... ... @@ -19,7 +19,7 @@
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8108" shutdown="SHUTDOWN">
<Server port="8107" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
... ... @@ -66,7 +66,7 @@
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8088" protocol="HTTP/1.1"
<Connector port="8087" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
... ... @@ -88,7 +88,7 @@
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8008" protocol="AJP/1.3" redirectPort="8443" />
<Connector port="8007" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
... ...
package com.yoho.search.restapi;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.service.BrandService;
import com.yoho.search.service.BrandSearchService;
import com.yoho.search.utils.ISearchConstans;
import com.yoho.search.utils.JsonUtil;
import com.yoho.search.utils.ParamUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -15,12 +14,12 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.service.BrandService;
import com.yoho.search.service.BrandSearchService;
import com.yoho.search.utils.JsonUtil;
@Controller
public class BrandController {
... ... @@ -34,7 +33,7 @@ public class BrandController {
@RequestMapping(value = "/brand/{brandId}")
@ResponseBody
public Map brand(@PathVariable Short brandId, HttpServletRequest request) {
public Map<String,Object> brand(@PathVariable Short brandId, HttpServletRequest request) {
try {
Brand brand = brandService.getById(brandId);
JSONObject json = new JSONObject();
... ... @@ -52,7 +51,7 @@ public class BrandController {
@RequestMapping(value = "/brand/{start}/{size}")
@ResponseBody
public Map brand(@PathVariable Integer start, @PathVariable Integer size, HttpServletRequest request) {
public Map<String,Object> brand(@PathVariable Integer start, @PathVariable Integer size, HttpServletRequest request) {
try {
List<Brand> brands = brandService.getBrandPageLists(start, size);
JSONObject json = new JSONObject();
... ... @@ -62,13 +61,12 @@ public class BrandController {
return errorReturn("list", null, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/brand/list")
@ResponseBody
public Map list(HttpServletRequest request) {
public Map<String,Object> list(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = brandSearchService.listNew();
return jsonMap;
... ... @@ -76,8 +74,8 @@ public class BrandController {
return errorReturn("list", paramMap, e.getMessage());
}
}
private Map errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
private Map<String,Object> errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
logger.error("[※查询]失败:[func={}][param={}][message={}]", funName, JsonUtil.toJson(paramMap), errorMessage);
Map<String, Object> rtnMap = new HashMap<String, Object>();
rtnMap.put("code", 400);
... ...
package com.yoho.search.restapi;
import com.yoho.search.service.SearchService;
import com.yoho.search.utils.JsonUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.yoho.search.service.SearchService;
import com.yoho.search.service.SearchSortSizeService;
import com.yoho.search.utils.JsonUtil;
import com.yoho.search.vo.SearchApiResult;
import com.yoho.search.vo.SizeSortReqBO;
/**
* 搜索web端
... ... @@ -22,179 +28,220 @@ import java.util.Map;
@RequestMapping("/")
public class SearchController {
private static Logger logger = LoggerFactory.getLogger(SearchController.class);
private static Logger logger = LoggerFactory.getLogger(SearchController.class);
@Autowired
SearchService searchService;
SearchService searchService;
@Autowired
SearchSortSizeService searchSortSizeService;
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/search")
@ResponseBody
public Map searchNew(HttpServletRequest request) {
@ResponseBody
public Map<String, Object> searchNew(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("searchNew", paramMap, e.getMessage());
return errorReturn("searchNew", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/discount")
@ResponseBody
public Map<String, Object> discount(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.discount(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("discount", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/recent")
@ResponseBody
public Map<String, Object> recent(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.recentShelveDay(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("recent", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/count")
@ResponseBody
public long searchCount(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
long count = searchService.searchCount(transParamType(paramMap));
return count;
} catch (Exception e) {
logger.error("[※查询]失败:" + e.getMessage());
Map<String, Object> rtnMap = new HashMap<String, Object>();
rtnMap.put("code", 400);
rtnMap.put("status", "error");
rtnMap.put("errmsg", e.getMessage());
return 0;
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/suggest")
@ResponseBody
public Map<String, Object> suggest(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.suggest(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("suggest", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/discount")
@ResponseBody
public Map discount(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.discount(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("discount", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/recent")
@ResponseBody
public Map recent(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.recentShelveDay(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("recent", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/count")
@ResponseBody
public long searchCount(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
long count = searchService.searchCount(transParamType(paramMap));
return count;
} catch (Exception e) {
logger.error("[※查询]失败:"+ e.getMessage());
Map<String, Object> rtnMap = new HashMap<String, Object>();
rtnMap.put("code", 400);
rtnMap.put("status", "error");
rtnMap.put("errmsg", e.getMessage());
return 0;
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/suggest")
@ResponseBody
public Map suggest(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.suggest(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("suggest", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/sortgroup")
@ResponseBody
public Map sortGroup(HttpServletRequest request) {
@ResponseBody
public Map<String, Object> sortGroup(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.sortGroup(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("sortGroup", paramMap, e.getMessage());
return errorReturn("sortGroup", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/brands")
@ResponseBody
public Map brands(HttpServletRequest request) {
@ResponseBody
public Map<String, Object> brands(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.brands(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("brands", paramMap, e.getMessage());
return errorReturn("brands", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/group_brands")
@ResponseBody
public Map groupBrands(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.groupBrands(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("groupBrands", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/new-shelve")
@ResponseBody
public Map newShelveProduct(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.newShelveProduct(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("newShelveProduct", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/new_product")
@ResponseBody
public Map newProduct(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.newProduct(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("newProduct", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/shops")
@ResponseBody
public Map shops(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.shops(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("shops", paramMap, e.getMessage());
}
}
private Map errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
logger.error("[※查询]失败:[func={}][param={}][message={}]", funName, JsonUtil.toJson(paramMap), errorMessage);
Map<String, Object> rtnMap = new HashMap<String, Object>();
rtnMap.put("code", 400);
rtnMap.put("status", "error");
rtnMap.put("errmsg", errorMessage);
return rtnMap; //new ModelAndView(ISearchConstans.JSON_VIEW_NAME, rtnMap);
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/group_brands")
@ResponseBody
public Map<String, Object> groupBrands(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.groupBrands(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("groupBrands", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/new-shelve")
@ResponseBody
public Map<String, Object> newShelveProduct(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.newShelveProduct(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("newShelveProduct", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/new_product")
@ResponseBody
public Map<String, Object> newProduct(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.newProduct(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("newProduct", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/shops")
@ResponseBody
public Map<String, Object> shops(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.shops(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("shops", paramMap, e.getMessage());
}
}
private Map<String, Object> errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
logger.error("[※查询]失败:[func={}][param={}][message={}]", funName, JsonUtil.toJson(paramMap), errorMessage);
Map<String, Object> rtnMap = new HashMap<String, Object>();
rtnMap.put("code", 400);
rtnMap.put("status", "error");
rtnMap.put("errmsg", errorMessage);
return rtnMap; // new ModelAndView(ISearchConstans.JSON_VIEW_NAME,
// rtnMap);
}
/**
* 将HttpServletRequest中被锁定的ParameterMap转化为普通的HashMap
* */
public static Map<String, String> transParamType(Map<String, Object> paramMap){
Map<String, String> rtnMap = new HashMap<String, String>();
Iterator<String> itKeys = paramMap.keySet().iterator();
while(itKeys.hasNext()){
String key = itKeys.next();
String val = ((String[])paramMap.get(key))[0];
rtnMap.put(key, val);
}
return rtnMap;
public static Map<String, String> transParamType(Map<String, Object> paramMap) {
Map<String, String> rtnMap = new HashMap<String, String>();
Iterator<String> itKeys = paramMap.keySet().iterator();
while (itKeys.hasNext()) {
String key = itKeys.next();
String val = ((String[]) paramMap.get(key))[0];
rtnMap.put(key, val);
}
return rtnMap;
}
/**
* 获取分类,以及分类下的型号
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/sort_sizes")
@ResponseBody
public SearchApiResult sort_sizes(@ModelAttribute SizeSortReqBO sizeSortReqBO) {
return searchSortSizeService.sortSizes(sizeSortReqBO);
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/sort_size_products")
@ResponseBody
public Map<String, Object> sort_size_products(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchSortSizeService.sortSizeProducts(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("sort_size_products", paramMap, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/group_shops")
@ResponseBody
public Map<String, Object> groupShops(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.groupShops(transParamType(paramMap));
return jsonMap;
} catch (Exception e) {
return errorReturn("groupShops", paramMap, e.getMessage());
}
}
}
... ...
package com.yoho.search.restapi;
import com.yoho.search.service.TblProductService;
import com.yoho.search.utils.ISearchConstans;
import com.yoho.search.utils.ParamUtils;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import com.yoho.search.service.TblProductService;
import com.yoho.search.utils.ParamUtils;
@Controller
public class TblProductController {
... ... @@ -25,7 +29,7 @@ public class TblProductController {
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/tblproduct/search")
@ResponseBody
public Map search(HttpServletRequest request) {
public Map<String,Object> search(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = tblProductService.search(ParamUtils.transParamType(paramMap));
... ... @@ -42,7 +46,7 @@ public class TblProductController {
@RequestMapping(method = RequestMethod.POST, value = "/tblproduct/update/{product_skn}")
@ResponseBody
public Map updateIndex(@PathVariable String product_skn, @RequestBody String json, HttpServletRequest request) {
public Map<String,Object> updateIndex(@PathVariable String product_skn, @RequestBody String json, HttpServletRequest request) {
try{
tblProductService.update(product_skn, json);
return getResultMap(200, product_skn, "update tblproduct product_skn=" + product_skn + " success");
... ...
package com.yoho.search.service;
import com.yoho.search.index.Index;
import com.yoho.search.index.IndexClient;
import com.yoho.search.index.SearchCallback;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.utils.ConvertUtils;
import com.yoho.search.utils.PriceRangeUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
... ... @@ -17,7 +16,13 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.index.Index;
import com.yoho.search.index.IndexClient;
import com.yoho.search.index.SearchCallback;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.utils.PriceRangeUtils;
/**
* Created by YOHO on 15-11-2.
... ... @@ -25,147 +30,149 @@ import java.util.*;
@Service
public class SearchBaseService {
@Autowired
private IndexService indexService;
/**
* 执行检索
*
* @param indexName
* @param searchParam
* @return SearchResult 返回检索结果
*/
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
SearchResult searchResult = null;
Index firstIndex = indexService.getIndex(indexName);
if (firstIndex != null) {
searchResult = indexService.execute(new SearchCallback<SearchResult>() {
@Override
public SearchResult execute(IndexClient indexClient) {
return indexClient.search(indexName, searchParam);
}
}, firstIndex);
}
return searchResult;
}
@Autowired
private IndexService indexService;
/**
* 执行检索
*
* @param indexName
* @param searchParam
* @return SearchResult 返回检索结果
*/
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
SearchResult searchResult = null;
Index firstIndex = indexService.getIndex(indexName);
if (firstIndex != null) {
searchResult = indexService.execute(new SearchCallback<SearchResult>() {
@Override
public SearchResult execute(IndexClient indexClient) {
return indexClient.search(indexName, searchParam);
}
}, firstIndex);
}
return searchResult;
}
//构造通用的检索条件
public BoolFilterBuilder buildFilter(BoolFilterBuilder boolFilterBuilder, Map<String, String> paramMap) {
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("filter_")) {
key = entry.getKey();
field = key.substring(7, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.must(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.must(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("not_filter_")) {
key = entry.getKey();
field = key.substring(11, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.mustNot(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.mustNot(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("range_gte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gte(entry.getValue()));
} else if (entry.getKey().startsWith("range_lte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lte(entry.getValue()));
} else if (entry.getKey().startsWith("range_gt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gt(entry.getValue()));
} else if (entry.getKey().startsWith("range_lt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lt(entry.getValue()));
}
}
return boolFilterBuilder;
}
// 构造通用的检索条件
public BoolFilterBuilder buildFilter(BoolFilterBuilder boolFilterBuilder, Map<String, String> paramMap) {
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("filter_")) {
key = entry.getKey();
field = key.substring(7, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.must(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.must(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("not_filter_")) {
key = entry.getKey();
field = key.substring(11, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.mustNot(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.mustNot(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("range_gte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gte(entry.getValue()));
} else if (entry.getKey().startsWith("range_lte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lte(entry.getValue()));
} else if (entry.getKey().startsWith("range_gt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gt(entry.getValue()));
} else if (entry.getKey().startsWith("range_lt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lt(entry.getValue()));
}
}
return boolFilterBuilder;
}
public List<AbstractAggregationBuilder> buildAggregations(Map<String, String> paramMap) {
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("agg_")) {
key = entry.getKey();
field = key.substring(4, key.length());
if ("goods_price".equals(field)) {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(10000).order(Terms.Order.term(true)));
} else {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(1000));
}
}
}
return list;
}
public List<AbstractAggregationBuilder> buildAggregations(Map<String, String> paramMap) {
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("agg_")) {
key = entry.getKey();
field = key.substring(4, key.length());
if ("goods_price".equals(field)) {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(10000).order(Terms.Order.term(true)));
} else {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(1000));
}
}
}
return list;
}
public List<Map<String, Object>> buildFilterResponseMap(MultiBucketsAggregation aggregation, String fieldName) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
while (itSizeAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itSizeAgg.next();
map = new HashMap<String, Object>();
map.put(fieldName, lt.getKey());
list.add(map);
}
return list;
}
public List<Map<String, Object>> buildFilterResponseMap(MultiBucketsAggregation aggregation, String fieldName) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
while (itSizeAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itSizeAgg.next();
map = new HashMap<String, Object>();
map.put(fieldName, lt.getKey());
list.add(map);
}
return list;
}
public Map<String, Object> getPriceResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> priceMap = new LinkedHashMap<String, Object>();
if (aggregation.getBuckets().isEmpty()) return priceMap;
Iterator<? extends MultiBucketsAggregation.Bucket> itPriceAgg = aggregation.getBuckets().iterator();
int size = aggregation.getBuckets().size();
float[] prePrice = new float[size];
int i = 0;
while (itPriceAgg.hasNext()) {
prePrice[i] = Float.parseFloat(itPriceAgg.next().getKey());
i++;
}
float maxPrice = prePrice[i - 1];
List<Integer> intervals = PriceRangeUtils.getPriceInterval(prePrice, maxPrice);
size = intervals.size();
int j = 0;
for (j = 0; j < size - 1; j++) {
if (j > 0) {
priceMap.put((intervals.get(j) + 1) + "," + intervals.get(j + 1), "¥" + (intervals.get(j) + 1) + "-" + intervals.get(j + 1));
} else {
priceMap.put(intervals.get(j) + "," + intervals.get(j + 1), "¥" + intervals.get(j) + "-" + intervals.get(j + 1));
}
}
priceMap.put((intervals.get(j) + 1) + ",99999", "¥" + intervals.get(j) + "以上");
return priceMap;
}
public Map<String, Object> getPriceResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> priceMap = new LinkedHashMap<String, Object>();
if (aggregation.getBuckets().isEmpty())
return priceMap;
Iterator<? extends MultiBucketsAggregation.Bucket> itPriceAgg = aggregation.getBuckets().iterator();
int size = aggregation.getBuckets().size();
float[] prePrice = new float[size];
int i = 0;
while (itPriceAgg.hasNext()) {
prePrice[i] = Float.parseFloat(itPriceAgg.next().getKey());
i++;
}
float maxPrice = prePrice[i - 1];
List<Integer> intervals = PriceRangeUtils.getPriceInterval(prePrice, maxPrice);
size = intervals.size();
int j = 0;
for (j = 0; j < size - 1; j++) {
if (j > 0) {
priceMap.put((intervals.get(j) + 1) + "," + intervals.get(j + 1), "¥" + (intervals.get(j) + 1) + "-" + intervals.get(j + 1));
} else {
priceMap.put(intervals.get(j) + "," + intervals.get(j + 1), "¥" + intervals.get(j) + "-" + intervals.get(j + 1));
}
}
priceMap.put((intervals.get(j) + 1) + ",99999", "¥" + intervals.get(j) + "以上");
return priceMap;
}
public Map<String, Object> getGenderResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> genderMap = new LinkedHashMap<String, Object>();
Iterator<? extends MultiBucketsAggregation.Bucket> itGenderAgg = aggregation.getBuckets().iterator();
while (itGenderAgg.hasNext()) {
MultiBucketsAggregation.Bucket ltGender = itGenderAgg.next();
String genderId = ltGender.getKey();
if ("1".equals(genderId)) {
genderMap.put("1,3", "BOYS");
} else if ("2".equals(genderId)) {
genderMap.put("2,3", "GIRLS");
} else {
genderMap.put("1,3", "BOYS");
genderMap.put("2,3", "GIRLS");
}
}
return genderMap;
}
public Map<String, Object> getGenderResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> genderMap = new LinkedHashMap<String, Object>();
Iterator<? extends MultiBucketsAggregation.Bucket> itGenderAgg = aggregation.getBuckets().iterator();
while (itGenderAgg.hasNext()) {
MultiBucketsAggregation.Bucket ltGender = itGenderAgg.next();
String genderId = ltGender.getKey();
if ("1".equals(genderId)) {
genderMap.put("1,3", "BOYS");
} else if ("2".equals(genderId)) {
genderMap.put("2,3", "GIRLS");
} else {
genderMap.put("1,3", "BOYS");
genderMap.put("2,3", "GIRLS");
}
}
return genderMap;
}
}
... ...
This diff could not be displayed because it is too large.
package com.yoho.search.service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.utils.ISearchConstans;
import com.yoho.search.utils.JsonUtil;
import com.yoho.search.vo.SearchApiResult;
import com.yoho.search.vo.SizeInfoVO;
import com.yoho.search.vo.SizeSortReqBO;
import com.yoho.search.vo.SortWithSizesVO;
@Service
public class SearchSortSizeService {
private static Logger logger = LoggerFactory.getLogger(SearchService.class);
@Autowired
private SearchService searchService;
/**
* 查询品类对应的size【断码】【库存>0】
*
* @param paramMap
* @return
*/
public SearchApiResult sortSizes(SizeSortReqBO sizeSortReqBO) {
try {
SearchParam searchParam = new SearchParam();
// 获取过滤条件
BoolFilterBuilder boolFilter = this.genBoolFilterBuilderForSortSize(sizeSortReqBO);
searchParam.setFiter(boolFilter);
// 按品类聚合
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
TermsBuilder tremsBuilder = AggregationBuilders.terms("sortIdAgg").field("smallSortId").size(500);// 小分类200多一点
tremsBuilder.subAggregation(AggregationBuilders.topHits("productSku").setSize(1));// 只取一个smallSortId对用的hits数据
tremsBuilder.subAggregation(AggregationBuilders.terms("sizeIdAgg").field("sizeId").size(100));// 尺码不多,100足够
list.add(tremsBuilder);
searchParam.setAggregationBuilders(list);
// 只取聚合的结果,不取hit
searchParam.setSearchType(SearchType.COUNT);
// 获取product_sku_index的聚合结果
SearchResult searchResult = searchService.doSearch(ISearchConstans.INDEX_NAME_STORAGE_SKU_INDEX, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
if (!aggMaps.containsKey("sortIdAgg")) {
return new SearchApiResult();
}
// 构造list的返回结果
List<SortWithSizesVO> sortWithSizeList = new ArrayList<SortWithSizesVO>();
// 处理es返回的数据
Collection<Integer> allSizeIds = new HashSet<Integer>();
MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("sortIdAgg");
Iterator<? extends Bucket> iterator = aggreation.getBuckets().iterator();
while (iterator.hasNext()) {
SortWithSizesVO sortWithSize = new SortWithSizesVO();
sortWithSizeList.add(sortWithSize);
Bucket sortBucket = iterator.next();
sortWithSize.setSmall_sort_id(Integer.valueOf(sortBucket.getKey()));
Aggregations aggregations = sortBucket.getAggregations();
// 获取smallSortId对应的middleSortId,maxSortId
TopHits productSkuTopHits = aggregations.get("productSku");
if (productSkuTopHits != null) {
SearchHit[] searchHits = productSkuTopHits.getHits().getHits();
SearchHit searchHit = searchHits[0];
// 从hit中获取maxSortId和middleSortId
Map<String, Object> source = searchHit.getSource();
Integer maxSortId = (Integer) source.get("maxSortId");
sortWithSize.setMax_sort_id(maxSortId == null ? 0 : maxSortId);
Integer middleSortId = (Integer) source.get("middleSortId");
sortWithSize.setMiddle_sort_id(middleSortId == null ? 0 : middleSortId);
}
// 获取小分类下对应的sizeId
Collection<Integer> sizeIds = this.getSizeIdFromSizeIdAgg(aggregations);
sortWithSize.setCount(sizeIds.size());
List<SizeInfoVO> sizes = new ArrayList<SizeInfoVO>();
for (Integer sizeId : sizeIds) {
SizeInfoVO sizeInfoVO = new SizeInfoVO();
sizeInfoVO.setSize_id(sizeId);
sizes.add(sizeInfoVO);
}
sortWithSize.setSizes(sizes);
// 存所有的sizeId,取sizeIndex里取名字
allSizeIds.addAll(sizeIds);
}
// 根据SizeId获取尺寸信息
Map<Integer, SizeInfoVO> sizeInfoMap = this.querySizeInfo(allSizeIds);
// 处理尺寸的名称
for (SortWithSizesVO sizeInfos : sortWithSizeList) {
List<SizeInfoVO> sizes = sizeInfos.getSizes();
for (SizeInfoVO sizeInfoVO : sizes) {
int sizeId = sizeInfoVO.getSize_id();
SizeInfoVO sizeInfoVOFromMap = sizeInfoMap.get(sizeId);
if (sizeInfoVOFromMap == null) {
sizeInfoVO.setSize_name("");
} else {
sizeInfoVO.setSize_name(sizeInfoVOFromMap.getSize_name());
}
}
}
Map<String, Object> data = new HashMap<String, Object>();
data.put("total", sortWithSizeList.size());
data.put("list", sortWithSizeList);
SearchApiResult searchApiResult = new SearchApiResult();
searchApiResult.setData(data);
return searchApiResult;
} catch (Exception e) {
return genErrorMsg("sortSizes", sizeSortReqBO, e);
}
}
private SearchApiResult genErrorMsg(String methodName, Object param, Exception e) {
logger.error("[※查询]失败:[func={}][param={}][message={}]", methodName, JsonUtil.toJson(param), e);
SearchApiResult result = new SearchApiResult();
result.setCode(400);
result.setMessage(e.getMessage());
result.setData(new JSONObject());
return result;
}
/**
* 获取某分类下/某型号的分类Id
*
* @param paramMap
* @return
* @throws Exception
*/
public Map<String, Object> sortSizeProducts(Map<String, String> paramMap) throws Exception {
SizeSortReqBO sizeSortReqBO = genSizeSortReqBOFromParamMap(paramMap);
// 构建bool
SearchParam searchParam = new SearchParam();
BoolFilterBuilder boolFilter = this.genBoolFilterBuilderForSortSize(sizeSortReqBO);
searchParam.setFiter(boolFilter);
// 按productSkn聚合
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
TermsBuilder tremsBuilder = AggregationBuilders.terms("productSknAgg").field("productSkn").size(2000);// 最多只取2000个productSkn
list.add(tremsBuilder);
searchParam.setAggregationBuilders(list);
// 只取聚合的结果,不取hit
searchParam.setSearchType(SearchType.COUNT);
// 获取结果
SearchResult searchResult = searchService.doSearch(ISearchConstans.INDEX_NAME_STORAGE_SKU_INDEX, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
if (!aggMaps.containsKey("productSknAgg")) {
return new HashMap<String, Object>();
}
// 构建聚合结果
Set<String> productSkns = new HashSet<String>();
MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("productSknAgg");
Iterator<? extends Bucket> iterator = aggreation.getBuckets().iterator();
while (iterator.hasNext()) {
Bucket sortBucket = iterator.next();
productSkns.add(String.valueOf(sortBucket.getKey()));
}
logger.info("get productSkn from storagesku index productSkn size is{}", productSkns.size());
StringBuilder sb = new StringBuilder();
for (String productSkn : productSkns) {
sb.append(productSkn).append(",");
}
String productIds = sb.toString();
paramMap.put(ISearchConstans.PARAM_SYNC_SKN, productIds);
return searchService.searchNew(paramMap);
}
/**
* @param paramMap
* @return
*/
private SizeSortReqBO genSizeSortReqBOFromParamMap(Map<String, String> paramMap) {
SizeSortReqBO sizeSortReqBO = new SizeSortReqBO();
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_BREAKING)) {
sizeSortReqBO.setBreaking(paramMap.get(ISearchConstans.PARAM_SEARCH_BREAKING));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_STORAGENUM)) {
sizeSortReqBO.setStorage_num(paramMap.get(ISearchConstans.PARAM_SEARCH_STORAGENUM));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_SMALLSORT)) {
sizeSortReqBO.setSort(paramMap.get(ISearchConstans.PARAM_SEARCH_SMALLSORT));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_SIZE)) {
sizeSortReqBO.setSize(paramMap.get(ISearchConstans.PARAM_SEARCH_SIZE));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_STATUS)) {
sizeSortReqBO.setProductStatus(paramMap.get(ISearchConstans.PARAM_SEARCH_STATUS));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_ATTRIBUTE_NOT)) {
sizeSortReqBO.setAttribute_not(paramMap.get(ISearchConstans.PARAM_SEARCH_ATTRIBUTE_NOT));
}
if (paramMap.containsKey(ISearchConstans.PARAM_SEARCH_GENDER)) {
sizeSortReqBO.setGender(paramMap.get(ISearchConstans.PARAM_SEARCH_GENDER));
}
return sizeSortReqBO;
}
/**
* product_sku索引[sort_breaking_storage_num]
*
* @param params
* @return
*/
private BoolFilterBuilder genBoolFilterBuilderForSortSize(SizeSortReqBO sizeSortReqBO) {
BoolFilterBuilder boolFilter = FilterBuilders.boolFilter();
boolFilter.must(FilterBuilders.termFilter("status", 1));
if (StringUtils.isNotBlank(sizeSortReqBO.getProductStatus())) {
boolFilter.must(FilterBuilders.termFilter("productStatus", sizeSortReqBO.getProductStatus()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getAttribute_not())) {
boolFilter.mustNot(FilterBuilders.termFilter("attribute", sizeSortReqBO.getAttribute_not()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getStorage_num())) {
boolFilter.must(FilterBuilders.rangeFilter("storageNum").gte(sizeSortReqBO.getStorage_num()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getBreaking())) {
boolFilter.must(FilterBuilders.termFilter("breaking", sizeSortReqBO.getBreaking()));
}
String sort = sizeSortReqBO.getSort();
if (StringUtils.isNotBlank(sort)) {
String[] smallSortIds = sort.split(",");
if (smallSortIds.length > 0) {
boolFilter.must(FilterBuilders.termsFilter("smallSortId", smallSortIds));
}
}
String size = sizeSortReqBO.getSize();
if (StringUtils.isNotBlank(size)) {
String[] sizeIds = size.split(",");
if (sizeIds.length > 0) {
boolFilter.must(FilterBuilders.termsFilter("sizeId", sizeIds));
}
}
String gender = sizeSortReqBO.getGender();
if (StringUtils.isNotBlank(gender)) {
String[] genderIds = gender.split(",");
if (genderIds.length > 0) {
boolFilter.must(FilterBuilders.termsFilter("gender", genderIds));
}
}
return boolFilter;
}
// 从聚合结果中获取全部的尺码ids
private Collection<Integer> getSizeIdFromSizeIdAgg(Aggregations aggregations) {
MultiBucketsAggregation sizeIdAgg = (MultiBucketsAggregation) aggregations.get("sizeIdAgg");
if (sizeIdAgg == null) {
return new ArrayList<Integer>();
}
Iterator<? extends Bucket> sizeIdIterator = sizeIdAgg.getBuckets().iterator();
List<Integer> sizeIds = new ArrayList<Integer>();
while (sizeIdIterator.hasNext()) {
Bucket sizeBucket = sizeIdIterator.next();
sizeIds.add(Integer.valueOf(sizeBucket.getKey()));
}
return sizeIds;
}
// 查询尺码索引以获取尺码信息
private Map<Integer, SizeInfoVO> querySizeInfo(Collection<Integer> sizeIds) {
SearchParam searchParam = new SearchParam();
BoolFilterBuilder boolFilter = FilterBuilders.boolFilter();
boolFilter.must(FilterBuilders.termsFilter("id", sizeIds));
searchParam.setFiter(boolFilter);
searchParam.setSize(sizeIds.size());
SearchResult searchResult = searchService.doSearch(ISearchConstans.INDEX_NAME_SIZE, searchParam);
Map<Integer, SizeInfoVO> sizeResult = new HashMap<Integer, SizeInfoVO>();
List<Map<String, Object>> sizeSearchResultList = searchResult.getResultList();
for (Map<String, Object> sizeSearchResult : sizeSearchResultList) {
Integer id = (Integer) sizeSearchResult.get("id");
String sizeName = (String) sizeSearchResult.get("sizeName");
if (id != null && sizeName != null) {
SizeInfoVO sizeInfoVo = new SizeInfoVO();
sizeInfoVo.setSize_id(id);
sizeInfoVo.setSize_name(sizeName);
sizeResult.put(id, sizeInfoVo);
}
}
return sizeResult;
}
}
... ...
package com.yoho.search.service;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.utils.ISearchConstans;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
... ... @@ -15,10 +16,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.utils.ISearchConstans;
/**
* Created by zhuzhu on 15-11-19.
... ... @@ -98,7 +99,7 @@ public class TblProductService extends SearchBaseService {
return jsonMap;
}
private Map buildFilterResult(Map<String, Aggregation> aggregationMap) {
private Map<String, Object> buildFilterResult(Map<String, Aggregation> aggregationMap) {
Map<String, Object> map = new HashMap<String, Object>();
String key;
String field;
... ...
package com.yoho.search.vo;
public class SearchApiResult {
private int code = 200;
private String message = "success";
private Object data;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
... ...
package com.yoho.search.vo;
public class SizeInfoVO {
private int size_id;
private String size_name;
public int getSize_id() {
return size_id;
}
public void setSize_id(int size_id) {
this.size_id = size_id;
}
public String getSize_name() {
return size_name;
}
public void setSize_name(String size_name) {
this.size_name = size_name;
}
}
... ...
package com.yoho.search.vo;
public class SizeSortReqBO {
private String breaking = "1";
private String storage_num = "1";
private String sort;// 小分类id,以逗号隔开
private String size;// 尺码 Id,以逗号隔开
private String gender;//性别 1-男 2-女 3-通用,以逗号分隔
private String productStatus = "1";// 1:商品上架
private String attribute_not = "2";// 1:非赠品 2:赠品
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getProductStatus() {
return productStatus;
}
public void setProductStatus(String productStatus) {
this.productStatus = productStatus;
}
public String getAttribute_not() {
return attribute_not;
}
public void setAttribute_not(String attribute_not) {
this.attribute_not = attribute_not;
}
public String getBreaking() {
return breaking;
}
public void setBreaking(String breaking) {
this.breaking = breaking;
}
public String getStorage_num() {
return storage_num;
}
public void setStorage_num(String storage_num) {
this.storage_num = storage_num;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
}
... ...
package com.yoho.search.vo;
import java.util.List;
public class SortWithSizesVO {
private int small_sort_id;
private int middle_sort_id;
private int max_sort_id;
private int count;
private List<SizeInfoVO> sizes;
public int getSmall_sort_id() {
return small_sort_id;
}
public void setSmall_sort_id(int small_sort_id) {
this.small_sort_id = small_sort_id;
}
public int getMiddle_sort_id() {
return middle_sort_id;
}
public void setMiddle_sort_id(int middle_sort_id) {
this.middle_sort_id = middle_sort_id;
}
public int getMax_sort_id() {
return max_sort_id;
}
public void setMax_sort_id(int max_sort_id) {
this.max_sort_id = max_sort_id;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<SizeInfoVO> getSizes() {
return sizes;
}
public void setSizes(List<SizeInfoVO> sizes) {
this.sizes = sizes;
}
}
... ...
search.es.cluster.name=yohosearch_test
search.es.servers=192.168.102.209:9300
#search.es.cluster.name=yohosearch_online
#search.es.servers=123.57.172.205:9300 123.57.172.107:9300 123.57.172.201:9300
search.index.number_of_replicas=2
search.index.refresh_interval=1
search.index.translog.flush_threshold_ops=5000
search.index.batch.limit=5000
search.index.batch.limit.tbl=2000
search.index.batch.max.thread.size=10
#\u8D85\u65F6\u65F6\u95F4\u914D\u7F6E
service.call.connectReqTimeout=10000
service.call.socketTimeout=10000
service.call.connectTimeout=10000
# ******************** redis servers ********************
redis.proxy.address=192.168.102.216
redis.proxy.auth=
redis.proxy.port = 6379
redis.readonly.proxy.address=192.168.102.216
redis.readonly.proxy.port=6379
redis.readonly.proxy.auth=
coupon.send.time.interval.sendOrderConfirmCoupon=604800
order.task.host=$order.task.host
zkAddress=192.168.102.205:2181
web.context=search
redis.server=192.168.102.216
redis.port=6379
redis.pool.maxTotal=100
redis.pool.maxIdle=100
... ... @@ -18,30 +30,35 @@ redis.pool.testWhileIdle=true
# ******************** redis servers ********************
#redis.proxy.address=192.168.102.205
redis.proxy.address=192.168.50.69
redis.proxy.port=6379
#password, can be empty
redis.proxy.auth=
redis.readonly.proxy.address=192.168.102.205
redis.readonly.proxy.port=6379
redis.readonly.proxy.auth=
mq.server=192.168.10.109
mq.server=192.168.102.208
mq.port=5672
mq.username=admin1
mq.password=123qwe
#mq.server=192.168.50.69
#mq.port=9646
#mq.username=yhb_mq
#mq.password=yhb_mq
mq.exchange=yoho_search
is.do.rebuild.index=false
is.do.rebuild.tbl.index=false
rabbit.mq.prefix=
tbl.product.private.key=a85bb0674e08986c6b115d5e3a4884fa
tbl.product.url=http://test.soa.global.yohobuy.com/product/api/v1/detail/
search.es.cluster.name=yohosearch_test
search.es.servers=192.168.102.209:9300 192.168.102.208:9300
search.index.number_of_replicas=2
search.index.refresh_interval=1
search.index.translog.flush_threshold_ops=5000
search.index.batch.limit=5000
search.index.batch.limit.tbl=2000
search.index.batch.max.thread.size=10
search.minimum.should.match=75%
search.operator=and
search.default.field=productName_ansj^10,brandName^500,brandDomain^100,brandNameCn^100,brandNameEn^100,maxSort^300,middleSort^500,smallSort^1000,searchField_ansj,productSkn_ansj,brandNameCn_pinyin^100,maxSort_pinyin^300,middleSort_pinyin^500,smallSort_pinyin^1000,productKeyword^500,searchField
\ No newline at end of file
is.do.rebuild.index=true
is.do.rebuild.tbl.index=true
rabbit.mq.prefix=no
search.default.field=productName_ansj^10,brandName^500,brandDomain^100,brandNameCn^100,brandNameEn^100,maxSort^300,middleSort^500,smallSort^1000,searchField_ansj,productSkn_ansj,brandNameCn_pinyin^100,maxSort_pinyin^300,middleSort_pinyin^500,smallSort_pinyin^1000,productKeyword^500,brandKeyword^500,searchField
search.script.score=_score+doc['sortWeight'].value*0.003+(100-doc['breakingRate'].value)/100 * doc['salesWithDateDiff'].value/pow((now-doc['shelveTime'].value)/3600+2,1.8)
search.script.lang=groovy
tbl.product.private.key=a85bb0674e08986c6b115d5e3a4884fa
tbl.product.url=http://test.soa.global.yohobuy.com/product/api/v1/detail/
keyword.user.choice.file=/Users/ming/source/logs/fake.csv
... ...
datasources:
yhb_search_2016:
yhb_search_2016:
servers:
- 192.168.102.209:3306
- 192.168.102.209:3306
username: dev
password: dev
readOnlyInSlave: true
\ No newline at end of file
- 192.168.102.216:3306
- 192.168.102.216:3306
username: yh_test
password: 9nm0icOwt6bMHjMusIfMLw==
\ No newline at end of file
... ...
... ... @@ -12,11 +12,11 @@
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/spring-mybatis-datasource.xml,classpath*:META-INF/spring/spring*.xml</param-value>
</context-param>
<!--spring profile: restful client is local or zookeeper-->
<!-- spring profile: restful client is local or zookeeper
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>local,production</param-value>
</context-param>
</context-param> -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/common/ok.jsp</url-pattern>
... ...