Pārlūkot izejas kodu

搜索批次时支持价格筛选

sunyj 8 gadi atpakaļ
vecāks
revīzija
357bb558a6

+ 34 - 3
search-console/src/main/java/com/uas/search/console/service/impl/SearchServiceImpl.java

@@ -44,7 +44,6 @@ import com.uas.search.console.util.SearchUtils;
 import com.uas.search.exception.SearchException;
 import com.uas.search.grouping.DistinctGroupCollector;
 import com.uas.search.model.PageParams;
-import com.uas.search.model.SPage;
 import com.uas.search.model.PageParams.FilterField;
 import com.uas.search.service.SearchService;
 import com.uas.search.sort.SimilarValuesFieldComparatorSource;
@@ -315,7 +314,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 				ids.add(Long.parseLong(componentId));
 				// System.out.println(indexSearcher.explain(booleanQuery,
 				// scoreDoc.doc).toString());
-				System.out.println(componentId + "\t" + scoreDoc.score);
+//				System.out.println(componentId + "\t" + scoreDoc.score);
 			}
 			map.put("componentIds", ids);
 			map.put("page", pageParams.getPage());
@@ -894,6 +893,38 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 							BooleanClause.Occur.FILTER);
 				}
 
+				// 价格筛选
+				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);
+				}
+
 			}
 			logger.info(booleanQuery.toString());
 
@@ -950,7 +981,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 				cmpIds.add(StringUtils.isEmpty(cmpId) ? null : Long.valueOf(cmpId));
 				String goId = document.get(SearchConstants.GOODS_GO_ID_FIELD);
 				goIds.add(StringUtils.isEmpty(goId) ? null : Long.valueOf(goId));
-				System.out.println(cmpId + "\t" + goId + "\t" + scoreDoc.score);
+//				System.out.println(cmpId + "\t" + goId + "\t" + scoreDoc.score);
 			}
 			map.put("componentIds", cmpIds);
 			map.put("goodsIds", goIds);

+ 1 - 1
search-console/src/main/webapp/WEB-INF/views/console.html

@@ -19,7 +19,7 @@
 					<li>search/componentIds?keyword=a&page=1&size=5&filters={"COMPONENT_KINDID":401,"COMPONENT_BRANDID":45,"COMPONENT_HAS_RESERVE":true,"COMPONENT_HAS_SAMPLE":true,"COMPONENT_HAS_ORIGINAL":true,"COMPONENT_HAS_INACTION_STOCK":true,"COMPONENT_PROPERTIES":{"275":"92%20dB","781":"Tube"}}</li>
 					<li><a target="_blank">search/componentIds?keyword=aaa</a></li>
 					<li><a target="_blank">search/components?keyword=aaa</a></li>
-					<li>search/goodsIds?keyword=aaa&page=1&size=8&filters={"GOODS_KINDID":401,"GOODS_BRANDID":45,"GOODS_STORE_TYPE":"DISTRIBUTION","GOODS_CRNAME":"RMB-USD"}&sort=[{"field":"GO_RESERVE","reverse":true},{"field":"GO_MINPRICERMB","reverse":true},{"field":"GO_MINPRICEUSD","reverse":true},{"field":"GO_SEARCH"}]</li>
+					<li>search/goodsIds?keyword=aaa&page=1&size=8&filters={"GOODS_KINDID":401,"GOODS_BRANDID":45,"GOODS_STORE_TYPE":"DISTRIBUTION","GOODS_CRNAME":"RMB-USD","GOODS_MINPRICERMB":0,"GOODS_MAXPRICERMB":10,"GOODS_MINPRICEUSD":0,"GOODS_MAXPRICEUSD":10}&sort=[{"field":"GO_RESERVE","reverse":true},{"field":"GO_MINPRICERMB","reverse":true},{"field":"GO_MINPRICEUSD","reverse":true},{"field":"GO_SEARCH"}]</li>
 					<li><a target="_blank">search/goodsIds?keyword=aaa</a></li>
 				</ol>