|
|
@@ -45,6 +45,98 @@ public class SearchServiceImpl implements SearchService {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class);
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询标准物料
|
|
|
+ *
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 尺寸
|
|
|
+ * @return idPage
|
|
|
+ * @throws IOException 输入异常
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SPage<Long> getStandardProductIds(String keyword, Integer page, Integer size) throws IOException {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ SPage<Document> documents = getStandardProductDocuments(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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询非标准物料
|
|
|
+ *
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 尺寸
|
|
|
+ * @return idPage
|
|
|
+ * @throws IOException 输入异常
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SPage<Long> getNonStandardProductIds(String keyword, Integer page, Integer size) throws IOException {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ SPage<Document> documents = getNonStandardProductDocuments(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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SPage<Document> getStandardProductDocuments(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_STANDARD_FIELD, String.valueOf(1))), 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> getNonStandardProductDocuments(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_STANDARD_FIELD, String.valueOf(0))), 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_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);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return 物料排序规则
|
|
|
+ */
|
|
|
+ private SortField sortProduct(String keyword) {
|
|
|
+ // id
|
|
|
+ return new SortField(SearchConstants.PRODUCT_PRIVATE_ID_FIELD, new StringFieldComparatorSource(keyword));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public SPage<Long> getKindIds(String keyword, Integer page, Integer size) throws IOException {
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
@@ -1549,6 +1641,12 @@ public class SearchServiceImpl implements SearchService {
|
|
|
booleanQuery.add(booleanQuery2, BooleanClause.Occur.FILTER);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public V_Products getProduct(Long id) throws IOException {
|
|
|
+ return DocumentToObjectUtils.toProduct(
|
|
|
+ SearchUtils.getDocumentById(SearchConstants.PRODUCTS_PRIVATE_TABLE_NAME, SearchConstants.PRODUCT_PRIVATE_ID_FIELD, id));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Kind getKind(Long id) throws IOException {
|
|
|
return DocumentToObjectUtils.toKind(
|