|
|
@@ -583,8 +583,9 @@ public class SearchServiceImpl implements SearchService {
|
|
|
|
|
|
List<Map<String, Object>> brands = new ArrayList<Map<String, Object>>();
|
|
|
// 品牌名称带有空格,并且中英文名并无一定顺序,因此对nameCn、nameEn均要搜索
|
|
|
- BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
try {
|
|
|
+ BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
+ logger.info(booleanQuery);
|
|
|
String[] keywords = brandName.split(" ");
|
|
|
for (String keyword : keywords) {
|
|
|
// 搜索nameCn
|
|
|
@@ -615,6 +616,59 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return brands;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<String> getSimilarPropertyValues(Long kindId, Long propertyId, String keyword, Long topNum) {
|
|
|
+ String message = "";
|
|
|
+ if (kindId == null || propertyId == null) {
|
|
|
+ message = "类目id或属性id为空";
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+ searcherManager.maybeReopen();
|
|
|
+ IndexSearcher searcher = searcherManager.get();
|
|
|
+ if (searcher == null) {
|
|
|
+ message = "获取索引文件失败";
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ String propertyIdString = String.valueOf(propertyId);
|
|
|
+ if (!propertyIdString.startsWith(SearchConstants.COMPONENT_PROPERTY_PREFIX)) {
|
|
|
+ propertyIdString = SearchConstants.COMPONENT_PROPERTY_PREFIX + propertyIdString;
|
|
|
+ }
|
|
|
+ if (keyword == null) {
|
|
|
+ keyword = "";
|
|
|
+ }
|
|
|
+ if (topNum == null || topNum < 1) {
|
|
|
+ topNum = (long) SIMILAR_NUM;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> propertyValues = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
+ booleanQuery.add(new TermQuery(new Term(SearchConstants.COMPONENT_KINDID_FIELD, String.valueOf(kindId))),
|
|
|
+ BooleanClause.Occur.MUST);
|
|
|
+ booleanQuery.add(new PrefixQuery(new Term(propertyIdString, keyword)), BooleanClause.Occur.MUST);
|
|
|
+ logger.info(booleanQuery);
|
|
|
+ TopDocs topDocs = searcher.search(booleanQuery, TOP_NUM);
|
|
|
+ ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
|
|
+ for (ScoreDoc scoreDoc : scoreDocs) {
|
|
|
+ Set<String> fieldsToLoad = new HashSet<>();
|
|
|
+ fieldsToLoad.add(propertyIdString);
|
|
|
+ Document document = searcher.doc(scoreDoc.doc, fieldsToLoad);
|
|
|
+ String propertyValue = document.get(propertyIdString);
|
|
|
+ if (!StringUtils.isEmpty(propertyValue) && !propertyValues.contains(propertyValue)) {
|
|
|
+ propertyValues.add(propertyValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return propertyValues;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据输入获取相似的器件原厂型号
|
|
|
*
|