|
|
@@ -48,6 +48,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
|
|
|
private static IndexSearcherManager searcherManager = new IndexSearcherManager();
|
|
|
|
|
|
+ @Override
|
|
|
public List<Long> getKindIds(String keyword) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -88,6 +89,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return ids;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public List<Map<String, Object>> getKinds(String keyword) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -131,6 +133,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return kinds;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public List<Long> getBrandIds(String keyword) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -171,6 +174,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return ids;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public List<Map<String, Object>> getBrands(String keyword) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -214,6 +218,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return brands;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Map<String, Object> getComponentIds(String keyword, PageParams page) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -227,6 +232,9 @@ public class SearchServiceImpl implements SearchService {
|
|
|
throw new RuntimeException("获取索引文件失败");
|
|
|
}
|
|
|
|
|
|
+ if (page == null) {
|
|
|
+ page = new PageParams();
|
|
|
+ }
|
|
|
if (page.getPage() == 0)
|
|
|
page.setPage(1);
|
|
|
if (page.getSize() == 0)
|
|
|
@@ -239,17 +247,34 @@ public class SearchServiceImpl implements SearchService {
|
|
|
keyword = keyword.toLowerCase();
|
|
|
PrefixQuery prefixQuery = new PrefixQuery(new Term(SearchConstants.COMPONENT_CODE_FIELD, keyword));
|
|
|
booleanQuery.add(prefixQuery, BooleanClause.Occur.MUST);
|
|
|
- if (!StringUtils.isEmpty(page.getFilters())) {
|
|
|
- if (!StringUtils.isEmpty(page.getFilters().get("kindId"))) {// 筛选类目
|
|
|
- String kindId = String.valueOf(page.getFilters().get("kindId"));
|
|
|
+
|
|
|
+ Map<String, Object> filters = page.getFilters();
|
|
|
+ if (!StringUtils.isEmpty(filters)) {
|
|
|
+ // 筛选类目
|
|
|
+ String kindId = String.valueOf(filters.remove("kindId"));
|
|
|
+ if (!StringUtils.isEmpty(kindId)) {
|
|
|
TermQuery kindQuery = new TermQuery(new Term(SearchConstants.COMPONENT_KINDID_FIELD, kindId));
|
|
|
booleanQuery.add(kindQuery, BooleanClause.Occur.MUST);
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(page.getFilters().get("brandId"))) {// 筛选品牌
|
|
|
- String brandId = String.valueOf(page.getFilters().get("brandId"));
|
|
|
+
|
|
|
+ // 筛选品牌
|
|
|
+ String brandId = String.valueOf(filters.remove("brandId"));
|
|
|
+ if (!StringUtils.isEmpty(brandId)) {
|
|
|
TermQuery brandQuery = new TermQuery(new Term(SearchConstants.COMPONENT_BRANDID_FIELD, brandId));
|
|
|
booleanQuery.add(brandQuery, BooleanClause.Occur.MUST);
|
|
|
}
|
|
|
+
|
|
|
+ // 属性过滤
|
|
|
+ for (String key : filters.keySet()) {
|
|
|
+ if (!key.startsWith(SearchConstants.COMPONENT_PROPERTY_PREFIX)) {
|
|
|
+ key = new StringBuilder(SearchConstants.COMPONENT_PROPERTY_PREFIX).append(key).toString();
|
|
|
+ }
|
|
|
+ String value = String.valueOf(filters.get(key));
|
|
|
+ if (!StringUtils.isEmpty(value)) {
|
|
|
+ TermQuery propertyQuery = new TermQuery(new Term(key, value));
|
|
|
+ booleanQuery.add(propertyQuery, BooleanClause.Occur.MUST);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
TopDocs hits;
|
|
|
@@ -280,6 +305,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Set<Long> getKindIdsBySearchComponent(String keyword, String brandId) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -324,6 +350,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return kindIds;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public List<Map<String, Object>> getKindsBySearchComponent(String keyword, String brandId) {
|
|
|
Set<Long> kindIds = getKindIdsBySearchComponent(keyword, brandId);
|
|
|
List<Map<String, Object>> kinds = new ArrayList<Map<String, Object>>();
|
|
|
@@ -361,6 +388,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return kinds;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Set<Long> getBrandIdsBySearchComponent(String keyword, String kindId) {
|
|
|
if (isKeywordInvalid(keyword)) {
|
|
|
throw new IllegalArgumentException("搜索关键词无效");
|
|
|
@@ -405,6 +433,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return brandIds;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public List<Map<String, Object>> getBrandsBySearchComponent(String keyword, String kindId) {
|
|
|
Set<Long> brandIds = getBrandIdsBySearchComponent(keyword, kindId);
|
|
|
List<Map<String, Object>> brands = new ArrayList<Map<String, Object>>();
|