|
|
@@ -63,7 +63,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
List<Long> ids = new ArrayList<Long>();
|
|
|
BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
ids.add(Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
}
|
|
|
@@ -78,7 +78,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
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(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> kind = new HashMap<String, Object>();
|
|
|
kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
@@ -100,7 +100,7 @@ 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(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
ids.add(Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
}
|
|
|
@@ -119,7 +119,7 @@ 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(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> brand = new HashMap<String, Object>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
@@ -135,7 +135,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
public Map<String, Object> getComponentIds(String keyword, PageParams page) {
|
|
|
// 因为器件、属性值的数据量远比类目、品牌大得多,而且器件搜索可能还需进行分页,
|
|
|
// 所以涉及器件、属性值的搜索,都不能像类目和品牌一样直接利用SearchUtils.getDocuments方法
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
|
|
|
if (page == null) {
|
|
|
page = new PageParams();
|
|
|
@@ -261,7 +261,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
|
|
|
Set<Long> kindIds = new HashSet<Long>();
|
|
|
try {
|
|
|
@@ -312,7 +312,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(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> kind = new HashMap<String, Object>();
|
|
|
kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
@@ -327,7 +327,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("搜索关键词无效:" + keyword);
|
|
|
}
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
|
|
|
Set<Long> brandIds = new HashSet<Long>();
|
|
|
try {
|
|
|
@@ -378,7 +378,7 @@ 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(booleanQuery);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> brand = new HashMap<String, Object>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
@@ -431,7 +431,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
if (SearchUtils.isKeywordInvalid(componentCode)) {
|
|
|
throw new SearchException("输入无效:" + componentCode);
|
|
|
}
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
|
|
|
List<Map<String, Object>> components = new ArrayList<>();
|
|
|
try {
|
|
|
@@ -480,7 +480,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
}
|
|
|
logger.info(booleanQuery.toString());
|
|
|
|
|
|
- List<Document> documents = SearchUtils.getDocuments(booleanQuery, SIMILAR_NUM);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery,
|
|
|
+ SIMILAR_NUM);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> brand = new HashMap<>();
|
|
|
brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
|
|
|
@@ -537,7 +538,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
}
|
|
|
}
|
|
|
logger.info(booleanQuery.toString());
|
|
|
- List<Document> documents = SearchUtils.getDocuments(booleanQuery, SIMILAR_NUM);
|
|
|
+ List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery, SIMILAR_NUM);
|
|
|
for (Document document : documents) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
|
|
|
@@ -555,7 +556,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
if (kindId == null || propertyId == null) {
|
|
|
throw new SearchException("类目id和属性id不能为空");
|
|
|
}
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
|
|
|
String propertyIdString = String.valueOf(propertyId);
|
|
|
if (!propertyIdString.startsWith(SearchConstants.COMPONENT_PROPERTY_PREFIX)) {
|
|
|
@@ -615,7 +616,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
* @return
|
|
|
*/
|
|
|
private List<String> getSimilarComponentCodes(String componentCode) {
|
|
|
- return getSimilarValues(SearchConstants.COMPONENT_CODE_FIELD, componentCode);
|
|
|
+ return getSimilarValues(SearchConstants.COMPONENT_TABLE_NAME, SearchConstants.COMPONENT_CODE_FIELD,
|
|
|
+ componentCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -626,7 +628,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
*/
|
|
|
private List<String> getSimilarBrandNames(String brandName) {
|
|
|
// 获取相似的中文品牌
|
|
|
- List<String> nameCns = getSimilarValues(SearchConstants.BRAND_NAMECN_FIELD, brandName);
|
|
|
+ List<String> nameCns = getSimilarValues(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_NAMECN_FIELD,
|
|
|
+ brandName);
|
|
|
// 相似的中文品牌数量足够,直接返回
|
|
|
if (nameCns != null && nameCns.size() == SIMILAR_NUM) {
|
|
|
return nameCns;
|
|
|
@@ -638,7 +641,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
}
|
|
|
|
|
|
// 获取相似的英文品牌
|
|
|
- List<String> nameEns = getSimilarValues(SearchConstants.BRAND_NAMEEN_FIELD, brandName);
|
|
|
+ List<String> nameEns = getSimilarValues(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_NAMEEN_FIELD,
|
|
|
+ brandName);
|
|
|
if (CollectionUtils.isEmpty(nameEns)) {
|
|
|
return names;
|
|
|
}
|
|
|
@@ -660,21 +664,22 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
* @return
|
|
|
*/
|
|
|
private List<String> getSimilarKindNames(String kindName) {
|
|
|
- return getSimilarValues(SearchConstants.KIND_NAMECN_FIELD, kindName);
|
|
|
+ return getSimilarValues(SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_NAMECN_FIELD, kindName);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据输入值获取该域相似的值
|
|
|
*
|
|
|
+ * @param tableName
|
|
|
* @param field
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<String> getSimilarValues(String field, String keyword) {
|
|
|
+ private List<String> getSimilarValues(String tableName, String field, String keyword) {
|
|
|
if (SearchUtils.isKeywordInvalid(keyword)) {
|
|
|
throw new SearchException("输入无效:" + keyword);
|
|
|
}
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
+ IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
|
|
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
try {
|
|
|
@@ -714,17 +719,20 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
|
|
|
@Override
|
|
|
public KindSimpleInfo getKind(Long id) {
|
|
|
- return DocumentToObjectUtils.toKind(SearchUtils.getDocumentById(SearchConstants.KIND_ID_FIELD, id));
|
|
|
+ return DocumentToObjectUtils.toKind(
|
|
|
+ SearchUtils.getDocumentById(SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_ID_FIELD, id));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public BrandSimpleInfo getBrand(Long id) {
|
|
|
- return DocumentToObjectUtils.toBrand(SearchUtils.getDocumentById(SearchConstants.BRAND_ID_FIELD, id));
|
|
|
+ return DocumentToObjectUtils.toBrand(
|
|
|
+ SearchUtils.getDocumentById(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_ID_FIELD, id));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ComponentSimpleInfo getComponent(Long id) {
|
|
|
- return DocumentToObjectUtils.toComponent(SearchUtils.getDocumentById(SearchConstants.COMPONENT_ID_FIELD, id));
|
|
|
+ return DocumentToObjectUtils.toComponent(SearchUtils.getDocumentById(SearchConstants.COMPONENT_TABLE_NAME,
|
|
|
+ SearchConstants.COMPONENT_ID_FIELD, id));
|
|
|
}
|
|
|
|
|
|
}
|