|
|
@@ -276,6 +276,16 @@ public class SearchServiceImpl implements com.uas.platform.b2b.search.SearchServ
|
|
|
*/
|
|
|
private static final int MAXPAGESIZE = 50;
|
|
|
|
|
|
+ /**
|
|
|
+ * 匹配中文正则式
|
|
|
+ */
|
|
|
+ private static final String CHINESE_REGEXP = "^[\u4e00-\u9fa5]*$";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配英文正则式
|
|
|
+ */
|
|
|
+ private static final String ENGLISH_REGEXP = "^[A-Za-z]+$";
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
private Field getPropertyField(Class<?> targetCls, String properyName) {
|
|
|
@@ -1024,52 +1034,145 @@ public class SearchServiceImpl implements com.uas.platform.b2b.search.SearchServ
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> getSimilarKinds(String keyword) {
|
|
|
- List<String> kindList = similarKinds(keyword);
|
|
|
- List<Kind> contents = new ArrayList<>();
|
|
|
- for (String kind : kindList) {
|
|
|
- List<Kind> temps = kindDao.findByNameCn(kind);
|
|
|
- if (!CollectionUtils.isEmpty(temps)) {
|
|
|
- contents.add(temps.get(0));
|
|
|
- } else { // 中文品牌找不到,找英文的
|
|
|
- temps = kindDao.findByNameEn(kind);
|
|
|
+ public List<Map<String, Object>> getSimilarBrandsByCode(String keyword) {
|
|
|
+ List<String> brandList = similarBrandsByCode(keyword);
|
|
|
+ List<Brand> contents = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> brands = new ArrayList<>();
|
|
|
+ for (String brand : brandList) {
|
|
|
+ if (keyword.matches(CHINESE_REGEXP)) {
|
|
|
+ List<Brand> temps = brandDao.findByNameCn(brand);
|
|
|
+ if (!CollectionUtils.isEmpty(temps)) {
|
|
|
+ contents.add(temps.get(0));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<Brand> temps = brandDao.findByNameEn(brand);
|
|
|
if (!CollectionUtils.isEmpty(temps)) {
|
|
|
contents.add(temps.get(0));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- List<Map<String, Object>> brands = new ArrayList<>();
|
|
|
- for (Kind kind : contents) {
|
|
|
+ for (Brand brand : contents) {
|
|
|
Map<String, Object> temp = new HashMap<>();
|
|
|
- temp.put("kindCn", kind.getNameCn());
|
|
|
- temp.put("kindEn", kind.getNameEn());
|
|
|
+ if (keyword.matches(CHINESE_REGEXP)) {
|
|
|
+ temp.put("brandName", brand.getNameCn());
|
|
|
+ } else {
|
|
|
+ temp.put("brandName", brand.getNameEn());
|
|
|
+ }
|
|
|
brands.add(temp);
|
|
|
}
|
|
|
return brands;
|
|
|
}
|
|
|
|
|
|
- private List<String> similarKinds(String keyword) {
|
|
|
- SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_cn");
|
|
|
- // 相似的类目中文名数量足够,直接返回
|
|
|
- List<String> kindCnList = kindCns.getContent();
|
|
|
- if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
|
|
|
- return kindCnList;
|
|
|
+ private List<String> similarBrandsByCode(String keyword) {
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
+ if (keyword.matches(CHINESE_REGEXP)) {
|
|
|
+ SPage<String> brandCns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
|
|
|
+ "br_name_cn");
|
|
|
+ // 相似的品牌中文名数量足够,直接返回
|
|
|
+ List<String> brandCnList = brandCns.getContent();
|
|
|
+ if (brandCnList != null && brandCnList.size() == SIMILAR_NUM) {
|
|
|
+ return brandCnList;
|
|
|
+ }
|
|
|
+ result = brandCnList;
|
|
|
+ } else if (keyword.matches(ENGLISH_REGEXP)) {
|
|
|
+ SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
|
|
|
+ "br_name_en");
|
|
|
+ List<String> brandEnList = brandEns.getContent();
|
|
|
+ if (brandEnList != null && brandEnList.size() == SIMILAR_NUM) {
|
|
|
+ return brandEnList;
|
|
|
+ }
|
|
|
+ result = brandEnList;
|
|
|
+ } else {
|
|
|
+ SPage<String> brandCns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
|
|
|
+ "br_name_cn");
|
|
|
+ // 相似的品牌中文名数量足够,直接返回
|
|
|
+ List<String> brandCnList = brandCns.getContent();
|
|
|
+ if (brandCnList != null && brandCnList.size() == SIMILAR_NUM) {
|
|
|
+ return brandCnList;
|
|
|
+ }
|
|
|
+ result = brandCnList;
|
|
|
+ // 获取相似品牌英文名
|
|
|
+ SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
|
|
|
+ "br_name_en");
|
|
|
+ List<String> brandEnList = brandEns.getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(brandEnList)) {
|
|
|
+ result.addAll(brandEnList);
|
|
|
+ // 如果总的数量超出SIMILAR_NUM,去除多余的元素
|
|
|
+ if (result.size() > SIMILAR_NUM) {
|
|
|
+ removeElements(result, SIMILAR_NUM);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- List<String> result = kindCnList;
|
|
|
- if (result == null) {
|
|
|
- result = new ArrayList<>();
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSimilarKinds(String keyword) {
|
|
|
+ List<String> kindList = similarKinds(keyword);
|
|
|
+ List<Kind> contents = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> kinds = new ArrayList<>();
|
|
|
+ for (String kind : kindList) {
|
|
|
+ if (keyword.matches(ENGLISH_REGEXP)) {
|
|
|
+ List<Kind> temps = kindDao.findByNameEn(kind);
|
|
|
+ if (!CollectionUtils.isEmpty(temps)) {
|
|
|
+ contents.add(temps.get(0));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<Kind> temps = kindDao.findByNameCn(kind);
|
|
|
+ if (!CollectionUtils.isEmpty(temps)) {
|
|
|
+ contents.add(temps.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ for (Kind kind : contents) {
|
|
|
+ Map<String, Object> temp = new HashMap<>();
|
|
|
+ if (keyword.matches(ENGLISH_REGEXP)) {
|
|
|
+ temp.put("kindName", kind.getNameEn());
|
|
|
+ } else {
|
|
|
+ temp.put("kindName", kind.getNameCn());
|
|
|
+ }
|
|
|
+ kinds.add(temp);
|
|
|
+ }
|
|
|
+ return kinds;
|
|
|
+ }
|
|
|
|
|
|
- // 获取相似类目英文名
|
|
|
- SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
|
|
|
- List<String> brandEnList = brandEns.getContent();
|
|
|
- if (!CollectionUtils.isEmpty(brandEnList)) {
|
|
|
- result.addAll(brandEnList);
|
|
|
- // 如果总的数量超出SIMILAR_NUM,去除多余的元素
|
|
|
- if (result.size() > SIMILAR_NUM) {
|
|
|
- removeElements(result, SIMILAR_NUM);
|
|
|
- return result;
|
|
|
+ private List<String> similarKinds(String keyword) {
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
+ if (keyword.matches(CHINESE_REGEXP)) {
|
|
|
+ SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name");
|
|
|
+ // 相似的类目中文名数量足够,直接返回
|
|
|
+ List<String> kindCnList = kindCns.getContent();
|
|
|
+ if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
|
|
|
+ return kindCnList;
|
|
|
+ }
|
|
|
+ result = kindCnList;
|
|
|
+ } else if (keyword.matches(ENGLISH_REGEXP)) {
|
|
|
+ SPage<String> kindEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
|
|
|
+ // 相似的类目中文名数量足够,直接返回
|
|
|
+ List<String> kindEnList = kindEns.getContent();
|
|
|
+ if (kindEnList != null && kindEnList.size() == SIMILAR_NUM) {
|
|
|
+ return kindEnList;
|
|
|
+ }
|
|
|
+ result = kindEnList;
|
|
|
+ } else {
|
|
|
+ SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name");
|
|
|
+ // 相似的类目中文名数量足够,直接返回
|
|
|
+ List<String> kindCnList = kindCns.getContent();
|
|
|
+ if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
|
|
|
+ return kindCnList;
|
|
|
+ }
|
|
|
+ result = kindCnList;
|
|
|
+ // 获取相似类目英文名
|
|
|
+ SPage<String> kindEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
|
|
|
+ List<String> kindEnList = kindEns.getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(kindEnList)) {
|
|
|
+ result.addAll(kindEnList);
|
|
|
+ // 如果总的数量超出SIMILAR_NUM,去除多余的元素
|
|
|
+ if (result.size() > SIMILAR_NUM) {
|
|
|
+ removeElements(result, SIMILAR_NUM);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return result;
|