|
|
@@ -14,10 +14,12 @@ import org.apache.lucene.index.Term;
|
|
|
import org.apache.lucene.search.BooleanClause;
|
|
|
import org.apache.lucene.search.BooleanQuery;
|
|
|
import org.apache.lucene.search.IndexSearcher;
|
|
|
+import org.apache.lucene.search.NumericRangeQuery;
|
|
|
import org.apache.lucene.search.PrefixQuery;
|
|
|
import org.apache.lucene.search.ScoreDoc;
|
|
|
import org.apache.lucene.search.TermQuery;
|
|
|
import org.apache.lucene.search.TopDocs;
|
|
|
+import org.apache.lucene.search.BooleanClause.Occur;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -156,22 +158,60 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
Map<String, Object> filters = page.getFilters();
|
|
|
if (!CollectionUtils.isEmpty(filters)) {
|
|
|
// 筛选类目
|
|
|
- if (!StringUtils.isEmpty(filters.get("kindId"))) {
|
|
|
- String kindId = filters.get("kindId").toString();
|
|
|
+ if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_KINDID_KEY))) {
|
|
|
+ String kindId = filters.get(com.uas.search.utils.SearchConstants.COMPONENT_KINDID_KEY).toString();
|
|
|
TermQuery kindQuery = new TermQuery(new Term(SearchConstants.COMPONENT_KINDID_FIELD, kindId));
|
|
|
booleanQuery.add(kindQuery, BooleanClause.Occur.MUST);
|
|
|
}
|
|
|
|
|
|
// 筛选品牌
|
|
|
- if (!StringUtils.isEmpty(filters.get("brandId"))) {
|
|
|
- String brandId = filters.get("brandId").toString();
|
|
|
+ if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_BRANDID_KEY))) {
|
|
|
+ String brandId = filters.get(com.uas.search.utils.SearchConstants.COMPONENT_BRANDID_KEY).toString();
|
|
|
TermQuery brandQuery = new TermQuery(new Term(SearchConstants.COMPONENT_BRANDID_FIELD, brandId));
|
|
|
booleanQuery.add(brandQuery, BooleanClause.Occur.MUST);
|
|
|
}
|
|
|
|
|
|
+ // 库存不为0
|
|
|
+ if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_RESERVE_KEY))) {
|
|
|
+ Boolean isReserveNotEmpty = (Boolean) filters
|
|
|
+ .get(com.uas.search.utils.SearchConstants.COMPONENT_RESERVE_KEY);
|
|
|
+ if (isReserveNotEmpty) {
|
|
|
+ booleanQuery.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_RESERVE_FIELD, 0.0,
|
|
|
+ Double.MAX_VALUE, false, true), BooleanClause.Occur.MUST);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 现货、呆滞库存、样品数量不为0,取或的关系
|
|
|
+ if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_SAMPLE_QTY_KEY))
|
|
|
+ || !StringUtils
|
|
|
+ .isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_ORIGINAL_QTY_KEY))
|
|
|
+ || !StringUtils.isEmpty(
|
|
|
+ filters.get(com.uas.search.utils.SearchConstants.COMPONENT_INACTION_STOCK_QTY_KEY))) {
|
|
|
+ BooleanQuery booleanQuery2 = new BooleanQuery();
|
|
|
+ if (!StringUtils
|
|
|
+ .isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_SAMPLE_QTY_KEY))) {
|
|
|
+ booleanQuery2.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_SAMPLE_QTY_FIELD,
|
|
|
+ 0.0, Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
|
|
|
+ }
|
|
|
+ if (!StringUtils
|
|
|
+ .isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_ORIGINAL_QTY_KEY))) {
|
|
|
+ booleanQuery2.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_ORIGINAL_QTY_FIELD,
|
|
|
+ 0.0, Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(
|
|
|
+ filters.get(com.uas.search.utils.SearchConstants.COMPONENT_INACTION_STOCK_QTY_KEY))) {
|
|
|
+ booleanQuery2.add(
|
|
|
+ NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_INACTION_STOCK_QTY_FIELD,
|
|
|
+ 0.0, Double.MAX_VALUE, false, true),
|
|
|
+ BooleanClause.Occur.SHOULD);
|
|
|
+ }
|
|
|
+ booleanQuery.add(booleanQuery2, Occur.MUST);
|
|
|
+ }
|
|
|
+
|
|
|
// 属性过滤
|
|
|
- if (!StringUtils.isEmpty(filters.get("properties"))) {
|
|
|
- JSONObject proJSON = FastjsonUtils.parseObject(String.valueOf(filters.get("properties")));
|
|
|
+ if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_PROPERTIES_KEY))) {
|
|
|
+ JSONObject proJSON = FastjsonUtils.parseObject(
|
|
|
+ String.valueOf(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_PROPERTIES_KEY)));
|
|
|
for (String key : proJSON.keySet()) {
|
|
|
String value = String.valueOf(proJSON.get(key));
|
|
|
if (!StringUtils.isEmpty(value)) {
|