|
|
@@ -283,13 +283,19 @@ public class SearchServiceImpl implements SearchService {
|
|
|
SPage<Map<String, Object>> sPage = new SPage<>(1, 1, 1, documents.getSize(), true, true);
|
|
|
// 精准匹配成功
|
|
|
if (!CollectionUtils.isEmpty(documents.getContent())) {
|
|
|
- List<String> keywordFeilds = new ArrayList<>();
|
|
|
- keywordFeilds.add(SearchConstants.GOODS_PR_PBRAND_EN_UNTOKENIZED_FIELD);
|
|
|
- keywordFeilds.add(SearchConstants.GOODS_PR_PBRAND_CN_UNTOKENIZED_FIELD);
|
|
|
-
|
|
|
+ Map<String, List<String>> keywordFeildsMap = new HashMap<>();
|
|
|
+ List<String> goodsFeilds = new ArrayList<>();
|
|
|
+ goodsFeilds.add(SearchConstants.GOODS_PR_PBRAND_EN_UNTOKENIZED_FIELD);
|
|
|
+ goodsFeilds.add(SearchConstants.GOODS_PR_PBRAND_CN_UNTOKENIZED_FIELD);
|
|
|
+
|
|
|
+ List<String> productsFeilds = new ArrayList<>();
|
|
|
+ productsFeilds.add(SearchConstants.PRODUCT_PRIVATE_PBRAND_CN_FIELD);
|
|
|
+ productsFeilds.add(SearchConstants.PRODUCT_PRIVATE_PBRAND_EN_FIELD);
|
|
|
+ keywordFeildsMap.put("goods", goodsFeilds);
|
|
|
+ keywordFeildsMap.put("products", productsFeilds);
|
|
|
brandIds.add(documents.getContent().get(0));
|
|
|
// 获取卖家信息
|
|
|
- Map<String, SPage<Object>> sellers = querySellers(keyword, keywordFeilds, page, size, false, SearchConstants.BRAND);
|
|
|
+ Map<String, SPage<Object>> sellers = querySellers(keyword, keywordFeildsMap, page, size, false, SearchConstants.BRAND);
|
|
|
stock = sellers.get("stock");
|
|
|
futures = sellers.get("futures");
|
|
|
|
|
|
@@ -314,9 +320,17 @@ public class SearchServiceImpl implements SearchService {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
SPage<Object> stock = null;
|
|
|
SPage<Object> futures = null;
|
|
|
- List<String> keywordFeilds = new ArrayList<>();
|
|
|
- keywordFeilds.add(SearchConstants.GOODS_PR_KIND_FIELD);
|
|
|
- Map<String, SPage<Object>> sellers = querySellers(keyword, keywordFeilds, page, size, true, SearchConstants.KIND);
|
|
|
+
|
|
|
+ Map<String, List<String>> keywordFeildsMap = new HashMap<>();
|
|
|
+ List<String> goodsFeilds = new ArrayList<>();
|
|
|
+ goodsFeilds.add(SearchConstants.GOODS_PR_KIND_FIELD);
|
|
|
+
|
|
|
+ List<String> productsFeilds = new ArrayList<>();
|
|
|
+ productsFeilds.add(SearchConstants.PRODUCT_PRIVATE_KIND_FIELD);
|
|
|
+ keywordFeildsMap.put("goods", goodsFeilds);
|
|
|
+ keywordFeildsMap.put("products", productsFeilds);
|
|
|
+
|
|
|
+ Map<String, SPage<Object>> sellers = querySellers(keyword, keywordFeildsMap, page, size, true, SearchConstants.KIND);
|
|
|
stock = sellers.get("stock");
|
|
|
futures = sellers.get("futures");
|
|
|
|
|
|
@@ -1120,19 +1134,24 @@ public class SearchServiceImpl implements SearchService {
|
|
|
// fieldsToLoad.add(SearchConstants.GOODS_CMP_ID_FIELD);
|
|
|
fieldsToLoad.add(SearchConstants.GOODS_GO_ID_FIELD);
|
|
|
ScoreDoc[] scoreDocs = hits.scoreDocs;
|
|
|
+ int totalHits = hits.totalHits;
|
|
|
for (ScoreDoc scoreDoc : scoreDocs) {
|
|
|
Document document = indexSearcher.doc(scoreDoc.doc, fieldsToLoad);
|
|
|
// String cmpId = document.get(SearchConstants.GOODS_CMP_ID_FIELD);
|
|
|
// cmpIds.add(StringUtils.isEmpty(cmpId) || cmpId.equals(ObjectToDocumentUtils.NULL_VALUE) ? null : Long.valueOf(cmpId));
|
|
|
String goId = document.get(SearchConstants.GOODS_GO_ID_FIELD);
|
|
|
- goIds.add(StringUtils.isEmpty(goId) || goId.equals(ObjectToDocumentUtils.NULL_VALUE) ? null : Long.valueOf(goId));
|
|
|
+ if (!StringUtils.isEmpty(goId) && !goId.equals(ObjectToDocumentUtils.NULL_VALUE)) {
|
|
|
+ goIds.add(Long.valueOf(goId));
|
|
|
+ } else {
|
|
|
+ totalHits--;
|
|
|
+ }
|
|
|
}
|
|
|
// map.put("componentIds", cmpIds);
|
|
|
map.put("content", goIds);
|
|
|
map.put("page", pageParams.getPage());
|
|
|
map.put("size", pageParams.getSize());
|
|
|
- map.put("totalElement", hits.totalHits);
|
|
|
- int totalPage = (int) Math.ceil(hits.totalHits / (1.0 * pageParams.getSize()));
|
|
|
+ map.put("totalElement", totalHits);
|
|
|
+ int totalPage = (int) Math.ceil(totalHits / (1.0 * pageParams.getSize()));
|
|
|
map.put("totalPage", totalPage);
|
|
|
map.put("last", totalPage == pageParams.getPage() ? true : false);
|
|
|
map.put("first", pageParams.getPage() == 1 ? true : false);
|
|
|
@@ -1627,7 +1646,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
* @param duplicate 去重类型
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, SPage<Object>> querySellers(String keyword, List<String> keywordFields, Integer page, Integer size, boolean tokenized, String duplicate) throws IOException {
|
|
|
+ private Map<String, SPage<Object>> querySellers(String keyword, Map<String, List<String>> keywordFields, Integer page, Integer size, boolean tokenized, String duplicate) throws IOException {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
@@ -1635,28 +1654,38 @@ public class SearchServiceImpl implements SearchService {
|
|
|
Map<String, SPage<Object>> map = new HashMap<>();
|
|
|
// 期货卖家
|
|
|
BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
-
|
|
|
+ // TODO 卖家排序
|
|
|
+ Sort sort = null;
|
|
|
// 未指定搜索的字段,则采用默认搜索逻辑
|
|
|
if (CollectionUtils.isEmpty(keywordFields)) {
|
|
|
Map<String, Query> boostQuerys = setSellersBoost(keyword);
|
|
|
} else {
|
|
|
- BooleanQuery booleanQuery2 = new BooleanQuery();
|
|
|
- for (String keywordField : keywordFields) {
|
|
|
+ BooleanQuery goodsBooleanQuery = new BooleanQuery();
|
|
|
+ for (String keywordField : keywordFields.get("goods")) {
|
|
|
if (!tokenized) {
|
|
|
- booleanQuery2.add(new TermQuery(new Term(keywordField, keyword.toLowerCase())), BooleanClause.Occur.SHOULD);
|
|
|
+ goodsBooleanQuery.add(new TermQuery(new Term(keywordField, keyword.toLowerCase())), BooleanClause.Occur.SHOULD);
|
|
|
} else {
|
|
|
- booleanQuery2.add(SearchUtils.getBooleanQuery(keywordField, keyword), BooleanClause.Occur.SHOULD);
|
|
|
+ goodsBooleanQuery.add(SearchUtils.getBooleanQuery(keywordField, keyword), BooleanClause.Occur.SHOULD);
|
|
|
}
|
|
|
- booleanQuery.add(booleanQuery2, Occur.MUST);
|
|
|
+ booleanQuery.add(goodsBooleanQuery, Occur.MUST);
|
|
|
+ // 现货卖家
|
|
|
+ map.put("stock", querySellers(SearchConstants.GOODS_TABLE_NAME, page, size, booleanQuery, sort, duplicate));
|
|
|
}
|
|
|
+
|
|
|
+ BooleanQuery productsBooleanQuery = new BooleanQuery();
|
|
|
+ for (String keywordField : keywordFields.get("products")) {
|
|
|
+ if (!tokenized) {
|
|
|
+ productsBooleanQuery.add(new TermQuery(new Term(keywordField, keyword.toLowerCase())), BooleanClause.Occur.SHOULD);
|
|
|
+ } else {
|
|
|
+ productsBooleanQuery.add(SearchUtils.getBooleanQuery(keywordField, keyword), BooleanClause.Occur.SHOULD);
|
|
|
+ }
|
|
|
+ booleanQuery.add(productsBooleanQuery, Occur.MUST);
|
|
|
+ // 期货卖家
|
|
|
+ map.put("futures", querySellers(SearchConstants.PRODUCTS_PRIVATE_TABLE_NAME, page, size, booleanQuery, sort, duplicate));
|
|
|
+ }
|
|
|
logger.info(booleanQuery.toString());
|
|
|
}
|
|
|
- // TODO 卖家排序
|
|
|
- Sort sort = null;
|
|
|
- // 现货卖家
|
|
|
- map.put("stock", querySellers(SearchConstants.GOODS_TABLE_NAME, page, size, booleanQuery, sort, duplicate));
|
|
|
- // 期货卖家
|
|
|
- map.put("futures", querySellers(SearchConstants.PRODUCTS_PRIVATE_TABLE_NAME, page, size, booleanQuery, sort, duplicate));
|
|
|
+
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@@ -1668,11 +1697,8 @@ public class SearchServiceImpl implements SearchService {
|
|
|
sPage.setPage(PAGE_INDEX);
|
|
|
sPage.setFirst(true);
|
|
|
}
|
|
|
- if (size != null && size > 0) {
|
|
|
- sPage.setSize(indexName.equals(SearchConstants.BRAND) ? BRAND_PAGE_SIZE : size);
|
|
|
- } else {
|
|
|
- sPage.setSize(indexName.equals(SearchConstants.BRAND) ? BRAND_PAGE_SIZE : PAGE_SIZE);
|
|
|
- }
|
|
|
+ size = size != null && size > 0 ? size : PAGE_SIZE;
|
|
|
+ sPage.setSize(duplicateType.equals(SearchConstants.BRAND) ? BRAND_PAGE_SIZE : size);
|
|
|
|
|
|
DuplicateFilter duplicateFilter = null;
|
|
|
if (!StringUtils.isEmpty(duplicateType)) {
|
|
|
@@ -1735,6 +1761,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
totalHits --;
|
|
|
}
|
|
|
}
|
|
|
+ // 按店铺批次数量排序
|
|
|
List<Map.Entry<String, List<Object>>> stuuids = new ArrayList<>(map.entrySet());
|
|
|
Collections.sort(stuuids, new Comparator<Map.Entry<String, List<Object>>> () {
|
|
|
@Override
|
|
|
@@ -1742,7 +1769,6 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return o1.getValue().size() - o2.getValue().size();
|
|
|
}
|
|
|
});
|
|
|
- size = size == null ? PAGE_SIZE : size;
|
|
|
for (int i = 0; i < (stuuids.size() < size ? stuuids.size() : size) ; i ++) {
|
|
|
content.add(stuuids.get(i).getKey());
|
|
|
}
|
|
|
@@ -1757,6 +1783,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
if (totalPage == sPage.getPage()) {
|
|
|
sPage.setLast(true);
|
|
|
}
|
|
|
+ sPage.setSize(size);
|
|
|
sPage.setTotalElement(totalHits);
|
|
|
sPage.setContent(content);
|
|
|
} finally {
|