Showing
7 changed files
with
51 additions
and
24 deletions
@@ -18,9 +18,6 @@ public class UfoSuggestionConstants { | @@ -18,9 +18,6 @@ public class UfoSuggestionConstants { | ||
18 | 18 | ||
19 | public static final List<String> IGNORE_BRAND_NAMES = Arrays.asList(""); | 19 | public static final List<String> IGNORE_BRAND_NAMES = Arrays.asList(""); |
20 | 20 | ||
21 | - /** | ||
22 | - * 返回智能搜索词的数量 | ||
23 | - */ | ||
24 | public static final int SMART_SUGGESTION_TERM_COUNT = 10; | 21 | public static final int SMART_SUGGESTION_TERM_COUNT = 10; |
25 | public static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | 22 | public static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; |
26 | 23 |
@@ -5,7 +5,6 @@ import com.yoho.search.base.utils.ProductIndexEsField; | @@ -5,7 +5,6 @@ import com.yoho.search.base.utils.ProductIndexEsField; | ||
5 | import com.yoho.search.base.utils.UfoProductIndexEsField; | 5 | import com.yoho.search.base.utils.UfoProductIndexEsField; |
6 | import com.yoho.search.consumer.common.IYohoIndexService; | 6 | import com.yoho.search.consumer.common.IYohoIndexService; |
7 | import com.yoho.search.consumer.ufosuggests.common.UfoKeywordType; | 7 | import com.yoho.search.consumer.ufosuggests.common.UfoKeywordType; |
8 | -import com.yoho.search.consumer.ufosuggests.common.UfoSuggestionConstants; | ||
9 | import com.yoho.search.consumer.ufosuggests.discover.UfoAbstractSuggestWordDiscoverer; | 8 | import com.yoho.search.consumer.ufosuggests.discover.UfoAbstractSuggestWordDiscoverer; |
10 | import com.yoho.search.core.es.model.SearchParam; | 9 | import com.yoho.search.core.es.model.SearchParam; |
11 | import com.yoho.search.core.es.model.SearchResult; | 10 | import com.yoho.search.core.es.model.SearchResult; |
@@ -59,7 +58,7 @@ public class UfoBrandAndSortNameSuggestWordDiscoverer extends UfoAbstractSuggest | @@ -59,7 +58,7 @@ public class UfoBrandAndSortNameSuggestWordDiscoverer extends UfoAbstractSuggest | ||
59 | return keywordSet; | 58 | return keywordSet; |
60 | } | 59 | } |
61 | 60 | ||
62 | - List<Short> brandIdList = brandList.stream().filter(brand -> !UfoSuggestionConstants.IGNORE_BRAND_NAMES.contains(brand.getBrandName())).map(Brand::getId).collect(Collectors.toList()); | 61 | + List<Short> brandIdList = brandList.stream().map(Brand::getId).collect(Collectors.toList()); |
63 | 62 | ||
64 | SearchParam searchParam = new SearchParam(); | 63 | SearchParam searchParam = new SearchParam(); |
65 | searchParam.setSize(0); | 64 | searchParam.setSize(0); |
@@ -7,7 +7,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; | @@ -7,7 +7,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
7 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; | 7 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; |
8 | import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude; | 8 | import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude; |
9 | 9 | ||
10 | -import java.util.Iterator; | ||
11 | import java.util.LinkedHashMap; | 10 | import java.util.LinkedHashMap; |
12 | import java.util.Map; | 11 | import java.util.Map; |
13 | 12 | ||
@@ -18,23 +17,15 @@ import java.util.Map; | @@ -18,23 +17,15 @@ import java.util.Map; | ||
18 | */ | 17 | */ |
19 | public abstract class UfoAbstractTokenAggregation extends AbstractAggregation { | 18 | public abstract class UfoAbstractTokenAggregation extends AbstractAggregation { |
20 | 19 | ||
21 | - protected int size; | ||
22 | - | ||
23 | - private long minDocCount; | 20 | + abstract String fieldName(); |
24 | 21 | ||
25 | - public UfoAbstractTokenAggregation() { | ||
26 | - this.size = 10000; | ||
27 | - this.minDocCount = 5; | ||
28 | - } | 22 | + abstract Integer size(); |
29 | 23 | ||
30 | - public UfoAbstractTokenAggregation(int size, long minDocCount) { | ||
31 | - this.size = size; | ||
32 | - this.minDocCount = minDocCount; | ||
33 | - } | 24 | + abstract Integer minDocCount(); |
34 | 25 | ||
35 | @Override | 26 | @Override |
36 | public AbstractAggregationBuilder<?> getBuilder() { | 27 | public AbstractAggregationBuilder<?> getBuilder() { |
37 | - return AggregationBuilders.terms(aggName()).field(fieldName()).size(size).minDocCount(minDocCount).includeExclude(new IncludeExclude(".{2,15}", null)); | 28 | + return AggregationBuilders.terms(aggName()).field(fieldName()).size(size()).minDocCount(minDocCount()).includeExclude(new IncludeExclude(".{2,15}", null)); |
38 | } | 29 | } |
39 | 30 | ||
40 | @Override | 31 | @Override |
@@ -44,15 +35,12 @@ public abstract class UfoAbstractTokenAggregation extends AbstractAggregation { | @@ -44,15 +35,12 @@ public abstract class UfoAbstractTokenAggregation extends AbstractAggregation { | ||
44 | return null; | 35 | return null; |
45 | } | 36 | } |
46 | 37 | ||
47 | - Map<String, Integer> countMap = new LinkedHashMap<>(size); | ||
48 | - Iterator<? extends MultiBucketsAggregation.Bucket> iterator = aggregation.getBuckets().iterator(); | ||
49 | - while (iterator.hasNext()) { | ||
50 | - MultiBucketsAggregation.Bucket buck = iterator.next(); | 38 | + Map<String, Integer> countMap = new LinkedHashMap<>(size()); |
39 | + for (MultiBucketsAggregation.Bucket buck : aggregation.getBuckets()) { | ||
51 | countMap.put(buck.getKeyAsString(), Integer.valueOf(String.valueOf(buck.getDocCount()))); | 40 | countMap.put(buck.getKeyAsString(), Integer.valueOf(String.valueOf(buck.getDocCount()))); |
52 | } | 41 | } |
53 | - | ||
54 | return countMap; | 42 | return countMap; |
55 | } | 43 | } |
56 | 44 | ||
57 | - abstract String fieldName(); | 45 | + |
58 | } | 46 | } |
@@ -23,4 +23,14 @@ public class UfoBrandKeywordTokenAggregation extends UfoAbstractTokenAggregation | @@ -23,4 +23,14 @@ public class UfoBrandKeywordTokenAggregation extends UfoAbstractTokenAggregation | ||
23 | public String filterName() { | 23 | public String filterName() { |
24 | return "ufoBrandKeyword"; | 24 | return "ufoBrandKeyword"; |
25 | } | 25 | } |
26 | + | ||
27 | + @Override | ||
28 | + public Integer size() { | ||
29 | + return 10000; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public Integer minDocCount() { | ||
34 | + return 1; | ||
35 | + } | ||
26 | } | 36 | } |
@@ -23,4 +23,14 @@ public class UfoProductKeywordTokenAggregation extends UfoAbstractTokenAggregati | @@ -23,4 +23,14 @@ public class UfoProductKeywordTokenAggregation extends UfoAbstractTokenAggregati | ||
23 | public String filterName() { | 23 | public String filterName() { |
24 | return "ufoProductKeyword"; | 24 | return "ufoProductKeyword"; |
25 | } | 25 | } |
26 | + | ||
27 | + @Override | ||
28 | + public Integer size() { | ||
29 | + return 10000; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public Integer minDocCount() { | ||
34 | + return 1; | ||
35 | + } | ||
26 | } | 36 | } |
@@ -24,5 +24,17 @@ public class UfoProductNameTokenAggregation extends UfoAbstractTokenAggregation | @@ -24,5 +24,17 @@ public class UfoProductNameTokenAggregation extends UfoAbstractTokenAggregation | ||
24 | return "ufoProductNameToken"; | 24 | return "ufoProductNameToken"; |
25 | } | 25 | } |
26 | 26 | ||
27 | + @Override | ||
28 | + public Integer size() { | ||
29 | + return 10000; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public Integer minDocCount() { | ||
34 | + return 5; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + | ||
27 | 39 | ||
28 | } | 40 | } |
@@ -3,6 +3,7 @@ package com.yoho.search.consumer.ufosuggests.discover.tokendiscover.agg; | @@ -3,6 +3,7 @@ package com.yoho.search.consumer.ufosuggests.discover.tokendiscover.agg; | ||
3 | import com.yoho.search.base.utils.UfoProductIndexEsField; | 3 | import com.yoho.search.base.utils.UfoProductIndexEsField; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | + * 系列关键词词条聚合 | ||
6 | * @author wangnan | 7 | * @author wangnan |
7 | * @version 2019/6/5 | 8 | * @version 2019/6/5 |
8 | */ | 9 | */ |
@@ -22,4 +23,14 @@ public class UfoSeriesKeywordTokenAggregation extends UfoAbstractTokenAggregatio | @@ -22,4 +23,14 @@ public class UfoSeriesKeywordTokenAggregation extends UfoAbstractTokenAggregatio | ||
22 | public String filterName() { | 23 | public String filterName() { |
23 | return "ufoSeriesKeyword"; | 24 | return "ufoSeriesKeyword"; |
24 | } | 25 | } |
26 | + | ||
27 | + @Override | ||
28 | + public Integer size() { | ||
29 | + return 10000; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public Integer minDocCount() { | ||
34 | + return 1; | ||
35 | + } | ||
25 | } | 36 | } |
-
Please register or login to post a comment