|
|
@@ -10,7 +10,10 @@ import com.uas.search.constant.model.SPage;
|
|
|
import com.uas.search.exception.SearchException;
|
|
|
import com.uas.search.grouping.DistinctGroupCollector;
|
|
|
import com.uas.search.grouping.GoodsGroupCollector;
|
|
|
-import com.uas.search.model.*;
|
|
|
+import com.uas.search.model.Brand;
|
|
|
+import com.uas.search.model.Component;
|
|
|
+import com.uas.search.model.Goods;
|
|
|
+import com.uas.search.model.Kind;
|
|
|
import com.uas.search.service.SearchService;
|
|
|
import com.uas.search.sort.StringFieldComparatorSource;
|
|
|
import com.uas.search.util.CollectionUtils;
|
|
|
@@ -29,7 +32,6 @@ import org.springframework.stereotype.Service;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.*;
|
|
|
-import java.util.Map.Entry;
|
|
|
|
|
|
/**
|
|
|
* 搜索索引
|
|
|
@@ -859,66 +861,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
List<Long> goIds = new ArrayList<>();
|
|
|
try {
|
|
|
BooleanQuery booleanQuery = queryGoods(keyword, keywordFields, tokenized);
|
|
|
- Map<FilterField, Object> filters = pageParams.getFilters();
|
|
|
- if (!CollectionUtils.isEmpty(filters)) {
|
|
|
- // 筛选类目
|
|
|
- if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_KINDID))) {
|
|
|
- filter(filters.get(FilterField.GOODS_KINDID), SearchConstants.GOODS_KI_ID_FIELD, booleanQuery);
|
|
|
- }
|
|
|
-
|
|
|
- // 筛选品牌
|
|
|
- if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_BRANDID))) {
|
|
|
- filter(filters.get(FilterField.GOODS_BRANDID), SearchConstants.GOODS_BR_ID_FIELD, booleanQuery);
|
|
|
- }
|
|
|
-
|
|
|
- // 筛选货源
|
|
|
- if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_STORE_TYPE))) {
|
|
|
- filter(filters.get(FilterField.GOODS_STORE_TYPE), SearchConstants.GOODS_ST_TYPE_FIELD, booleanQuery);
|
|
|
- }
|
|
|
-
|
|
|
- // 筛选货币
|
|
|
- if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_CRNAME))) {
|
|
|
- filter(filters.get(FilterField.GOODS_CRNAME), SearchConstants.GOODS_CRNAME_FIELD, booleanQuery);
|
|
|
- }
|
|
|
-
|
|
|
- // 筛选状态
|
|
|
- if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_STATUS))) {
|
|
|
- filter(filters.get(FilterField.GOODS_STATUS), SearchConstants.GOODS_GO_STATUS_FIELD, booleanQuery);
|
|
|
- }
|
|
|
-
|
|
|
- // 价格筛选
|
|
|
- Object minPriceRmb = filters.get(FilterField.GOODS_MINPRICERMB);
|
|
|
- Object maxPriceRmb = filters.get(FilterField.GOODS_MAXPRICERMB);
|
|
|
- Object minPriceUsd = filters.get(FilterField.GOODS_MINPRICEUSD);
|
|
|
- Object maxPriceUsd = filters.get(FilterField.GOODS_MAXPRICEUSD);
|
|
|
- // 筛选人民币价格
|
|
|
- if (!StringUtils.isEmpty(minPriceRmb) || !StringUtils.isEmpty(maxPriceRmb)) {
|
|
|
- Double minPrice = null;
|
|
|
- Double maxPrice = null;
|
|
|
- if (!StringUtils.isEmpty(minPriceRmb)) {
|
|
|
- minPrice = Double.valueOf(minPriceRmb.toString());
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(maxPriceRmb)) {
|
|
|
- maxPrice = Double.valueOf(maxPriceRmb.toString());
|
|
|
- }
|
|
|
- booleanQuery.add(NumericRangeQuery.newDoubleRange(SearchConstants.GOODS_GO_MINPRICERMB_FIELD,
|
|
|
- minPrice, maxPrice, true, true), BooleanClause.Occur.FILTER);
|
|
|
- }
|
|
|
- // 筛选美元价格
|
|
|
- if (!StringUtils.isEmpty(minPriceUsd) || !StringUtils.isEmpty(maxPriceUsd)) {
|
|
|
- Double minPrice = null;
|
|
|
- Double maxPrice = null;
|
|
|
- if (!StringUtils.isEmpty(minPriceUsd)) {
|
|
|
- minPrice = Double.valueOf(minPriceUsd.toString());
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(maxPriceUsd)) {
|
|
|
- maxPrice = Double.valueOf(maxPriceUsd.toString());
|
|
|
- }
|
|
|
- booleanQuery.add(NumericRangeQuery.newDoubleRange(SearchConstants.GOODS_GO_MINPRICEUSD_FIELD,
|
|
|
- minPrice, maxPrice, true, true), BooleanClause.Occur.FILTER);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ setGoodsFilter(pageParams.getFilters(), booleanQuery);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
|
|
|
// 排序
|
|
|
@@ -1014,6 +957,74 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置批次过滤条件
|
|
|
+ *
|
|
|
+ * @param filters 指定的过滤条件
|
|
|
+ * @param query 原查询
|
|
|
+ */
|
|
|
+ private void setGoodsFilter(Map<FilterField, Object> filters, BooleanQuery query) {
|
|
|
+ if (CollectionUtils.isEmpty(filters)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 筛选类目
|
|
|
+ if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_KINDID))) {
|
|
|
+ filter(filters.get(FilterField.GOODS_KINDID), SearchConstants.GOODS_KI_ID_FIELD, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选品牌
|
|
|
+ if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_BRANDID))) {
|
|
|
+ filter(filters.get(FilterField.GOODS_BRANDID), SearchConstants.GOODS_BR_ID_FIELD, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选货源
|
|
|
+ if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_STORE_TYPE))) {
|
|
|
+ filter(filters.get(FilterField.GOODS_STORE_TYPE), SearchConstants.GOODS_ST_TYPE_FIELD, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选货币
|
|
|
+ if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_CRNAME))) {
|
|
|
+ filter(filters.get(FilterField.GOODS_CRNAME), SearchConstants.GOODS_CRNAME_FIELD, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选状态
|
|
|
+ if (!StringUtils.isEmpty(filters.get(FilterField.GOODS_STATUS))) {
|
|
|
+ filter(filters.get(FilterField.GOODS_STATUS), SearchConstants.GOODS_GO_STATUS_FIELD, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 价格筛选
|
|
|
+ Object minPriceRmb = filters.get(FilterField.GOODS_MINPRICERMB);
|
|
|
+ Object maxPriceRmb = filters.get(FilterField.GOODS_MAXPRICERMB);
|
|
|
+ Object minPriceUsd = filters.get(FilterField.GOODS_MINPRICEUSD);
|
|
|
+ Object maxPriceUsd = filters.get(FilterField.GOODS_MAXPRICEUSD);
|
|
|
+ // 筛选人民币价格
|
|
|
+ if (!StringUtils.isEmpty(minPriceRmb) || !StringUtils.isEmpty(maxPriceRmb)) {
|
|
|
+ Double minPrice = null;
|
|
|
+ Double maxPrice = null;
|
|
|
+ if (!StringUtils.isEmpty(minPriceRmb)) {
|
|
|
+ minPrice = Double.valueOf(minPriceRmb.toString());
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(maxPriceRmb)) {
|
|
|
+ maxPrice = Double.valueOf(maxPriceRmb.toString());
|
|
|
+ }
|
|
|
+ query.add(NumericRangeQuery.newDoubleRange(SearchConstants.GOODS_GO_MINPRICERMB_FIELD,
|
|
|
+ minPrice, maxPrice, true, true), BooleanClause.Occur.FILTER);
|
|
|
+ }
|
|
|
+ // 筛选美元价格
|
|
|
+ if (!StringUtils.isEmpty(minPriceUsd) || !StringUtils.isEmpty(maxPriceUsd)) {
|
|
|
+ Double minPrice = null;
|
|
|
+ Double maxPrice = null;
|
|
|
+ if (!StringUtils.isEmpty(minPriceUsd)) {
|
|
|
+ minPrice = Double.valueOf(minPriceUsd.toString());
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(maxPriceUsd)) {
|
|
|
+ maxPrice = Double.valueOf(maxPriceUsd.toString());
|
|
|
+ }
|
|
|
+ query.add(NumericRangeQuery.newDoubleRange(SearchConstants.GOODS_GO_MINPRICEUSD_FIELD,
|
|
|
+ minPrice, maxPrice, true, true), BooleanClause.Occur.FILTER);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return 批次排序规则
|
|
|
*/
|
|
|
@@ -1081,29 +1092,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
try {
|
|
|
BooleanQuery booleanQuery = queryGoods(keyword, keywordFields, tokenized);
|
|
|
- // 过滤
|
|
|
- Set<Entry<FilterField, Object>> entrySet = filters.entrySet();
|
|
|
- for (Entry<FilterField, Object> entry : entrySet) {
|
|
|
- switch (entry.getKey()) {
|
|
|
- case GOODS_KINDID:
|
|
|
- filter(entry.getValue(), SearchConstants.GOODS_KI_ID_FIELD, booleanQuery);
|
|
|
- break;
|
|
|
- case GOODS_BRANDID:
|
|
|
- filter(entry.getValue(), SearchConstants.GOODS_BR_ID_FIELD, booleanQuery);
|
|
|
- break;
|
|
|
- case GOODS_STORE_TYPE:
|
|
|
- filter(entry.getValue(), SearchConstants.GOODS_ST_TYPE_FIELD, booleanQuery);
|
|
|
- break;
|
|
|
- case GOODS_CRNAME:
|
|
|
- filter(entry.getValue(), SearchConstants.GOODS_CRNAME_FIELD, booleanQuery);
|
|
|
- break;
|
|
|
- case GOODS_STATUS:
|
|
|
- filter(entry.getValue(), SearchConstants.GOODS_GO_STATUS_FIELD, booleanQuery);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new SearchException("不支持该过滤字段:" + entry.getKey());
|
|
|
- }
|
|
|
- }
|
|
|
+ setGoodsFilter(filters, booleanQuery);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
|
|
|
// 统计
|