|
|
@@ -480,7 +480,37 @@ public class SearchServiceImpl implements SearchService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<String> getSimilarComponentCodes(String componentCode) {
|
|
|
+ public List<Map<String, Object>> getSimilarComponents(String componentCode) {
|
|
|
+ if (isKeywordInvalid(componentCode)) {
|
|
|
+ throw new IllegalArgumentException("输入无效");
|
|
|
+ }
|
|
|
+ searcherManager.maybeReopen();
|
|
|
+ IndexSearcher indexSearcher = searcherManager.get();
|
|
|
+ if (indexSearcher == null) {
|
|
|
+ throw new RuntimeException("获取索引文件失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ BooleanQuery booleanQuery = getBooleanQuery(SearchConstants.COMPONENT_CODE_FIELD, componentCode);
|
|
|
+ TopDocs hits = indexSearcher.search(booleanQuery, SIMILAR_NUM);
|
|
|
+ ScoreDoc[] scoreDocs = hits.scoreDocs;
|
|
|
+ for (ScoreDoc scoreDoc : scoreDocs) {
|
|
|
+ Document document = indexSearcher.doc(scoreDoc.doc);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("cmp_id", document.get(SearchConstants.COMPONENT_ID_FIELD));
|
|
|
+ map.put("cmp_code", document.get(SearchConstants.COMPONENT_CODE_FIELD));
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ searcherManager.release(indexSearcher);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getSimilarComponentCodes(String componentCode) {
|
|
|
return getSimilarValues(SearchConstants.COMPONENT_CODE_FIELD, componentCode);
|
|
|
}
|
|
|
|