|
|
@@ -675,94 +675,43 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
|
|
|
|
|
|
@Override
|
|
|
public KindSimpleInfo getKind(Long kindId) {
|
|
|
- if (kindId == null) {
|
|
|
- throw new SearchException("输入无效:" + kindId);
|
|
|
- }
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
-
|
|
|
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) {
|
|
|
- throw new SearchException("索引中存在不止一个类目:kindId=" + kindId);
|
|
|
- } 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 {
|
|
|
- SearchUtils.releaseIndexSearcher(indexSearcher);
|
|
|
+ Document document = SearchUtils.getDocumentById(SearchConstants.KIND_ID_FIELD, kindId);
|
|
|
+ if (document != null) {
|
|
|
+ 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)));
|
|
|
}
|
|
|
return kind;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public BrandSimpleInfo getBrand(Long brandId) {
|
|
|
- if (brandId == null) {
|
|
|
- throw new SearchException("输入无效:" + brandId);
|
|
|
- }
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
-
|
|
|
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) {
|
|
|
- throw new SearchException("索引中存在不止一个品牌:brandId=" + brandId);
|
|
|
- } 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 {
|
|
|
- SearchUtils.releaseIndexSearcher(indexSearcher);
|
|
|
+ Document document = SearchUtils.getDocumentById(SearchConstants.BRAND_ID_FIELD, brandId);
|
|
|
+ if (document != null) {
|
|
|
+ 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));
|
|
|
}
|
|
|
return brand;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ComponentSimpleInfo getComponent(Long componentId) {
|
|
|
- if (componentId == null) {
|
|
|
- throw new SearchException("输入无效:" + componentId);
|
|
|
- }
|
|
|
- IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
|
|
|
-
|
|
|
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) {
|
|
|
- throw new SearchException("索引中存在不止一个器件:componentId=" + componentId);
|
|
|
- } 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 {
|
|
|
- SearchUtils.releaseIndexSearcher(indexSearcher);
|
|
|
+ Document document = SearchUtils.getDocumentById(SearchConstants.COMPONENT_ID_FIELD, componentId);
|
|
|
+ if (document != null) {
|
|
|
+ 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)));
|
|
|
}
|
|
|
return component;
|
|
|
}
|