|
@@ -45,6 +45,28 @@ public class SearchServiceImpl implements SearchService {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class);
|
|
private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询所有物料
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param keyword 关键词
|
|
|
|
|
+ * @param page 页码
|
|
|
|
|
+ * @param size 尺寸
|
|
|
|
|
+ * @return idPage
|
|
|
|
|
+ * @throws IOException 输入异常
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SPage<Long> getProductIds(Long enUU, String keyword, Integer page, Integer size) throws IOException {
|
|
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
|
|
+ SPage<Document> documents = getProductDocuments(enUU, keyword, page, size);
|
|
|
|
|
+ SPage<Long> sPage = new SPage<>(documents.getTotalPage(), documents.getTotalElement(), documents.getPage(),
|
|
|
|
|
+ documents.getSize(), documents.isFirst(), documents.isLast());
|
|
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
|
|
+ ids.add(Long.parseLong(document.get(SearchConstants.PRODUCT_PRIVATE_ID_FIELD)));
|
|
|
|
|
+ }
|
|
|
|
|
+ sPage.setContent(ids);
|
|
|
|
|
+ return sPage;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询标准物料
|
|
* 查询标准物料
|
|
|
*
|
|
*
|
|
@@ -89,6 +111,26 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return sPage;
|
|
return sPage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private SPage<Document> getProductDocuments(Long enUU, String keyword, Integer page, Integer size) throws IOException {
|
|
|
|
|
+// if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
|
|
+// throw new IllegalArgumentException("搜索关键词无效:" + keyword);
|
|
|
|
|
+// }
|
|
|
|
|
+ BooleanQuery q1 = new BooleanQuery();
|
|
|
|
|
+ q1.add(new TermQuery(new Term(SearchConstants.PRODUCT_PRIVATE_ENUU_FIELD, String.valueOf(enUU))), BooleanClause.Occur.MUST);
|
|
|
|
|
+ q1.add(new TermQuery(new Term(SearchConstants.PRODUCT_PRIVATE_B2CENABLED_FIELD, String.valueOf(1))), BooleanClause.Occur.MUST);
|
|
|
|
|
+ BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
|
|
+ booleanQuery.add(q1, BooleanClause.Occur.MUST);
|
|
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
|
|
+ BooleanQuery q2 = new BooleanQuery();
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_KIND_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_PBRANDEN_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_PCMPCODE_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
+ booleanQuery.add(q2, BooleanClause.Occur.MUST);
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.info(booleanQuery.toString());
|
|
|
|
|
+ return SearchUtils.getDocuments(SearchConstants.PRODUCTS_PRIVATE_TABLE_NAME, booleanQuery, new Sort(sortProduct(keyword)), page, size);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private SPage<Document> getStandardProductDocuments(Long enUU, String keyword, Integer page, Integer size) throws IOException {
|
|
private SPage<Document> getStandardProductDocuments(Long enUU, String keyword, Integer page, Integer size) throws IOException {
|
|
|
// if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
// if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
// throw new IllegalArgumentException("搜索关键词无效:" + keyword);
|
|
// throw new IllegalArgumentException("搜索关键词无效:" + keyword);
|
|
@@ -122,9 +164,9 @@ public class SearchServiceImpl implements SearchService {
|
|
|
booleanQuery.add(q1, BooleanClause.Occur.MUST);
|
|
booleanQuery.add(q1, BooleanClause.Occur.MUST);
|
|
|
if (!StringUtils.isEmpty(keyword)) {
|
|
if (!StringUtils.isEmpty(keyword)) {
|
|
|
BooleanQuery q2 = new BooleanQuery();
|
|
BooleanQuery q2 = new BooleanQuery();
|
|
|
- q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_TITLE_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
- q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_BRAND_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
- q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_CMPCODE_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_KIND_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_PBRANDEN_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
|
|
+ q2.add(createQuery(SearchConstants.PRODUCT_PRIVATE_PCMPCODE_FIELD, keyword, true,1), BooleanClause.Occur.SHOULD);
|
|
|
booleanQuery.add(q2, BooleanClause.Occur.MUST);
|
|
booleanQuery.add(q2, BooleanClause.Occur.MUST);
|
|
|
}
|
|
}
|
|
|
logger.info(booleanQuery.toString());
|
|
logger.info(booleanQuery.toString());
|