|
|
@@ -30,6 +30,10 @@ import org.wltea.analyzer.lucene.IKAnalyzer;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.search.console.core.exception.SystemError;
|
|
|
import com.uas.search.console.core.util.FastjsonUtils;
|
|
|
+import com.uas.search.console.model.BrandSimpleInfo;
|
|
|
+import com.uas.search.console.model.ComponentSimpleInfo;
|
|
|
+import com.uas.search.console.model.KindSimpleInfo;
|
|
|
+import com.uas.search.console.service.InnerSearchService;
|
|
|
import com.uas.search.console.support.IndexSearcherManager;
|
|
|
import com.uas.search.console.util.SearchConstants;
|
|
|
import com.uas.search.model.PageParams;
|
|
|
@@ -42,7 +46,7 @@ import com.uas.search.service.SearchService;
|
|
|
* @since 2016年8月5日 下午2:21:26
|
|
|
*/
|
|
|
@Service
|
|
|
-public class SearchServiceImpl implements SearchService {
|
|
|
+public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
|
|
|
/**
|
|
|
* 默认搜索的最大的记录条数
|
|
|
@@ -749,6 +753,8 @@ public class SearchServiceImpl implements SearchService {
|
|
|
removeElements(propertyValues, topNum.intValue());
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ searcherManager.release(searcher);
|
|
|
}
|
|
|
|
|
|
List<Map<String, String>> result = new ArrayList<>();
|
|
|
@@ -917,4 +923,131 @@ public class SearchServiceImpl implements SearchService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public KindSimpleInfo getKind(Long kindId) {
|
|
|
+ String message = "";
|
|
|
+ if (kindId == null) {
|
|
|
+ message = "输入无效:" + kindId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+ searcherManager.maybeReopen();
|
|
|
+ IndexSearcher indexSearcher = searcherManager.get();
|
|
|
+ if (indexSearcher == null) {
|
|
|
+ message = "获取索引文件失败";
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ KindSimpleInfo kind = null;
|
|
|
+ try {
|
|
|
+ TermQuery query = new TermQuery(new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(kindId)));
|
|
|
+ TopDocs topDocs = indexSearcher.search(query, 1);
|
|
|
+ int totalHits = topDocs.totalHits;
|
|
|
+ if (totalHits > 1) {
|
|
|
+ message = "索引中存在不止一个类目:kindId=" + kindId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ } else if (totalHits == 1) {
|
|
|
+ Document document = indexSearcher.doc(topDocs.scoreDocs[0].doc);
|
|
|
+ kind = new KindSimpleInfo();
|
|
|
+ kind.setId(kindId);
|
|
|
+ kind.setNameCn(document.get(SearchConstants.KIND_NAMECN_FIELD));
|
|
|
+ kind.setIsLeaf(Short.valueOf(document.get(SearchConstants.KIND_ISLEAF_FIELD)));
|
|
|
+ kind.setLevel(Short.valueOf(document.get(SearchConstants.KIND_LEVEL_FIELD)));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ searcherManager.release(indexSearcher);
|
|
|
+ }
|
|
|
+ return kind;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BrandSimpleInfo getBrand(Long brandId) {
|
|
|
+ String message = "";
|
|
|
+ if (brandId == null) {
|
|
|
+ message = "输入无效:" + brandId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+ searcherManager.maybeReopen();
|
|
|
+ IndexSearcher indexSearcher = searcherManager.get();
|
|
|
+ if (indexSearcher == null) {
|
|
|
+ message = "获取索引文件失败";
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ BrandSimpleInfo brand = null;
|
|
|
+ try {
|
|
|
+ TermQuery query = new TermQuery(new Term(SearchConstants.BRAND_ID_FIELD, String.valueOf(brandId)));
|
|
|
+ TopDocs topDocs = indexSearcher.search(query, 1);
|
|
|
+ int totalHits = topDocs.totalHits;
|
|
|
+ if (totalHits > 1) {
|
|
|
+ message = "索引中存在不止一个品牌:brandId=" + brandId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ } else if (totalHits == 1) {
|
|
|
+ Document document = indexSearcher.doc(topDocs.scoreDocs[0].doc);
|
|
|
+ brand = new BrandSimpleInfo();
|
|
|
+ brand.setId(brandId);
|
|
|
+ brand.setNameCn(document.get(SearchConstants.BRAND_NAMECN_FIELD));
|
|
|
+ brand.setNameEn(document.get(SearchConstants.BRAND_NAMEEN_FIELD));
|
|
|
+ brand.setUuid(document.get(SearchConstants.BRAND_UUID_FIELD));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ searcherManager.release(indexSearcher);
|
|
|
+ }
|
|
|
+ return brand;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ComponentSimpleInfo getComponent(Long componentId) {
|
|
|
+ String message = "";
|
|
|
+ if (componentId == null) {
|
|
|
+ message = "输入无效:" + componentId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+ searcherManager.maybeReopen();
|
|
|
+ IndexSearcher indexSearcher = searcherManager.get();
|
|
|
+ if (indexSearcher == null) {
|
|
|
+ message = "获取索引文件失败";
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ ComponentSimpleInfo component = null;
|
|
|
+ try {
|
|
|
+ TermQuery query = new TermQuery(new Term(SearchConstants.COMPONENT_ID_FIELD, String.valueOf(componentId)));
|
|
|
+ TopDocs topDocs = indexSearcher.search(query, 1);
|
|
|
+ int totalHits = topDocs.totalHits;
|
|
|
+ if (totalHits > 1) {
|
|
|
+ message = "索引中存在不止一个器件:componentId=" + componentId;
|
|
|
+ logger.error(message);
|
|
|
+ throw new SystemError(message);
|
|
|
+ } else if (totalHits == 1) {
|
|
|
+ Document document = indexSearcher.doc(topDocs.scoreDocs[0].doc);
|
|
|
+ component = new ComponentSimpleInfo();
|
|
|
+ component.setId(componentId);
|
|
|
+ component.setCode(document.get(SearchConstants.COMPONENT_CODE_FIELD));
|
|
|
+ component.setUuid(document.get(SearchConstants.COMPONENT_UUID_FIELD));
|
|
|
+ component.setKindid(Long.valueOf(document.get(SearchConstants.COMPONENT_KINDID_FIELD)));
|
|
|
+ component.setBrandid(Long.valueOf(document.get(SearchConstants.COMPONENT_BRANDID_FIELD)));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ searcherManager.release(indexSearcher);
|
|
|
+ }
|
|
|
+ return component;
|
|
|
+ }
|
|
|
+
|
|
|
}
|