|
|
@@ -69,83 +69,70 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class);
|
|
|
|
|
|
@Override
|
|
|
- public List<Long> getKindIds(String keyword) {
|
|
|
- return getKindIds(keyword, Occur.MUST);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据关键字搜索产品类目id
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * 关键词
|
|
|
- * @param occur
|
|
|
- * @return 符合条件的类目id
|
|
|
- */
|
|
|
- private List<Long> getKindIds(String keyword, Occur occur) {
|
|
|
+ public SPage<Long> getKindIds(String keyword, Integer page, Integer size) {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
List<Long> ids = new ArrayList<Long>();
|
|
|
- BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword, occur);
|
|
|
+ BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
- for (Document document : documents) {
|
|
|
+ SPage<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery, page, size);
|
|
|
+ SPage<Long> sPage = new SPage<Long>(documents.getTotalPage(), documents.getTotalElement(), documents.getPage(),
|
|
|
+ documents.getSize(), documents.isFirst(), documents.isLast());
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
ids.add(Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
}
|
|
|
- return ids;
|
|
|
+ sPage.setContent(ids);
|
|
|
+ return sPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> getKinds(String keyword) {
|
|
|
+ public SPage<Map<String, Object>> getKinds(String keyword, Integer page, Integer size) {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
List<Map<String, Object>> kinds = new ArrayList<Map<String, Object>>();
|
|
|
BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
- for (Document document : documents) {
|
|
|
+ SPage<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery, page, size);
|
|
|
+ SPage<Map<String, Object>> sPage = new SPage<Map<String, Object>>(documents.getTotalPage(),
|
|
|
+ documents.getTotalElement(), documents.getPage(), documents.getSize(), documents.isFirst(),
|
|
|
+ documents.isLast());
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
Map<String, Object> kind = new HashMap<String, Object>();
|
|
|
kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
kind.put("nameCn", document.get(SearchConstants.KIND_NAMECN_FIELD));
|
|
|
kinds.add(kind);
|
|
|
}
|
|
|
- return kinds;
|
|
|
+ sPage.setContent(kinds);
|
|
|
+ return sPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Long> getBrandIds(String keyword) {
|
|
|
- return getBrandIds(keyword, Occur.MUST);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据关键字搜索产品品牌id
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * 关键词
|
|
|
- * @param occur
|
|
|
- * @return 符合条件的品牌id
|
|
|
- */
|
|
|
- private List<Long> getBrandIds(String keyword, Occur occur) {
|
|
|
+ public SPage<Long> getBrandIds(String keyword, Integer page, Integer size) {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
List<Long> ids = new ArrayList<Long>();
|
|
|
BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
- booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMECN_FIELD, keyword, occur),
|
|
|
+ booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMECN_FIELD, keyword),
|
|
|
BooleanClause.Occur.SHOULD);
|
|
|
- booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMEEN_FIELD, keyword, occur),
|
|
|
+ booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMEEN_FIELD, keyword),
|
|
|
BooleanClause.Occur.SHOULD);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
- for (Document document : documents) {
|
|
|
+ SPage<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery, page,
|
|
|
+ size);
|
|
|
+ SPage<Long> sPage = new SPage<Long>(documents.getTotalPage(), documents.getTotalElement(), documents.getPage(),
|
|
|
+ documents.getSize(), documents.isFirst(), documents.isLast());
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
ids.add(Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
}
|
|
|
- return ids;
|
|
|
+ sPage.setContent(ids);
|
|
|
+ return sPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> getBrands(String keyword) {
|
|
|
+ public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
@@ -156,8 +143,12 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMEEN_FIELD, keyword),
|
|
|
BooleanClause.Occur.SHOULD);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
- for (Document document : documents) {
|
|
|
+ SPage<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery, page,
|
|
|
+ size);
|
|
|
+ SPage<Map<String, Object>> sPage = new SPage<Map<String, Object>>(documents.getTotalPage(),
|
|
|
+ documents.getTotalElement(), documents.getPage(), documents.getSize(), documents.isFirst(),
|
|
|
+ documents.isLast());
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
Map<String, Object> brand = new HashMap<String, Object>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
brand.put("uuid", document.get(SearchConstants.BRAND_UUID_FIELD));
|
|
|
@@ -165,7 +156,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
brand.put("nameEn", document.get(SearchConstants.BRAND_NAMEEN_FIELD));
|
|
|
brands.add(brand);
|
|
|
}
|
|
|
- return brands;
|
|
|
+ sPage.setContent(brands);
|
|
|
+ return sPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -402,7 +394,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
booleanQuery.add(new TermQuery(new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(kindId))),
|
|
|
BooleanClause.Occur.SHOULD);
|
|
|
}
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery).getContent();
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> kind = new HashMap<String, Object>();
|
|
|
kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
@@ -458,7 +450,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
booleanQuery.add(new TermQuery(new Term(SearchConstants.BRAND_ID_FIELD, String.valueOf(brandId))),
|
|
|
BooleanClause.Occur.SHOULD);
|
|
|
}
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery)
|
|
|
+ .getContent();
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> brand = new HashMap<String, Object>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
@@ -560,8 +553,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
}
|
|
|
logger.info(booleanQuery.toString());
|
|
|
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery,
|
|
|
- SIMILAR_NUM);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery)
|
|
|
+ .getContent();
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> brand = new HashMap<>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
@@ -618,7 +611,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
}
|
|
|
}
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery, SIMILAR_NUM);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery).getContent();
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|