使用系数的方式解决csBrandKeyword
Showing
5 changed files
with
37 additions
and
37 deletions
@@ -6,6 +6,7 @@ import java.util.List; | @@ -6,6 +6,7 @@ import java.util.List; | ||
6 | import java.util.Map; | 6 | import java.util.Map; |
7 | import java.util.stream.Collectors; | 7 | import java.util.stream.Collectors; |
8 | 8 | ||
9 | +import com.yoho.search.common.utils.SearchKeyWordUtils; | ||
9 | import org.apache.commons.collections.MapUtils; | 10 | import org.apache.commons.collections.MapUtils; |
10 | import org.apache.commons.lang.StringUtils; | 11 | import org.apache.commons.lang.StringUtils; |
11 | import org.elasticsearch.common.lucene.search.function.CombineFunction; | 12 | import org.elasticsearch.common.lucene.search.function.CombineFunction; |
@@ -132,7 +133,7 @@ public class FunctionScoreSearchHelper { | @@ -132,7 +133,7 @@ public class FunctionScoreSearchHelper { | ||
132 | 133 | ||
133 | // 模糊搜索页的打分器 | 134 | // 模糊搜索页的打分器 |
134 | private List<IScorer> getFuzzyPageScorers(BoolQueryBuilder persionalFilter, Map<String, String> paramMap) { | 135 | private List<IScorer> getFuzzyPageScorers(BoolQueryBuilder persionalFilter, Map<String, String> paramMap) { |
135 | - List<IScorer> scorers = new ArrayList<IScorer>(); | 136 | + List<IScorer> scorers = new ArrayList<>(); |
136 | // 1、不是默认搜索类页,返回空列表 | 137 | // 1、不是默认搜索类页,返回空列表 |
137 | if (!searchCommonHelper.isFuzzySearchPageDefault(paramMap)) { | 138 | if (!searchCommonHelper.isFuzzySearchPageDefault(paramMap)) { |
138 | return scorers; | 139 | return scorers; |
@@ -141,11 +142,15 @@ public class FunctionScoreSearchHelper { | @@ -141,11 +142,15 @@ public class FunctionScoreSearchHelper { | ||
141 | scorers.addAll(this.getCommonScorers(persionalFilter, paramMap)); | 142 | scorers.addAll(this.getCommonScorers(persionalFilter, paramMap)); |
142 | // 3、添加首次上架时间的打分器 | 143 | // 3、添加首次上架时间的打分器 |
143 | scorers.add(searchScorerFactory.getFirstShelveTimeScorer(FUZZY_FIRST_SHELVE_SCORE)); | 144 | scorers.add(searchScorerFactory.getFirstShelveTimeScorer(FUZZY_FIRST_SHELVE_SCORE)); |
144 | - //scorers.add(searchScorerFactory.getNewProductScorer(90)); | ||
145 | // 4、添加频道搜索 | 145 | // 4、添加频道搜索 |
146 | scorers.add(searchScorerFactory.getChannelSearchScorer(paramMap)); | 146 | scorers.add(searchScorerFactory.getChannelSearchScorer(paramMap)); |
147 | // 5、添加线下可售商品打分器 | 147 | // 5、添加线下可售商品打分器 |
148 | scorers.add(searchScorerFactory.getOfflineSaleOnlyScorer()); | 148 | scorers.add(searchScorerFactory.getOfflineSaleOnlyScorer()); |
149 | + // 6、添加关键词完全匹配的打分器 | ||
150 | + String query = MapUtils.getString(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY); | ||
151 | + if(StringUtils.isNotBlank(query)){ | ||
152 | + scorers.add(searchScorerFactory.getCsBrandKeyWordScorer(query)); | ||
153 | + } | ||
149 | return scorers; | 154 | return scorers; |
150 | } | 155 | } |
151 | 156 |
@@ -110,8 +110,8 @@ public class SearchScorerFactory { | @@ -110,8 +110,8 @@ public class SearchScorerFactory { | ||
110 | return new OfflineSaleOnlyScorer(); | 110 | return new OfflineSaleOnlyScorer(); |
111 | } | 111 | } |
112 | 112 | ||
113 | - // 获取新品的打分器 | ||
114 | - public IScorer getNewProductScorer(int dayLimit) { | ||
115 | - return new NewProductScorer(dayLimit); | 113 | + // 获取CsBrandKeyWord的打分器 |
114 | + public IScorer getCsBrandKeyWordScorer(String query) { | ||
115 | + return new CsBrandKeyWordScorer(query); | ||
116 | } | 116 | } |
117 | } | 117 | } |
1 | +package com.yoho.search.service.scorer.impl; | ||
2 | + | ||
3 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
4 | +import com.yoho.search.models.YohoFilterFunctionBuilders; | ||
5 | +import com.yoho.search.service.scorer.IScorer; | ||
6 | +import org.elasticsearch.index.query.QueryBuilders; | ||
7 | +import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; | ||
8 | + | ||
9 | +public class CsBrandKeyWordScorer implements IScorer { | ||
10 | + | ||
11 | + private static final float NEW_PRODUCT_WEIGHT = 10; | ||
12 | + private String keyword; | ||
13 | + | ||
14 | + public CsBrandKeyWordScorer(String keyword){ | ||
15 | + this.keyword = keyword; | ||
16 | + } | ||
17 | + | ||
18 | + @Override | ||
19 | + public void addScorer(YohoFilterFunctionBuilders yohoFilterFunctionBuilders) { | ||
20 | + yohoFilterFunctionBuilders.add(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword,keyword), ScoreFunctionBuilders.weightFactorFunction(NEW_PRODUCT_WEIGHT)); | ||
21 | + } | ||
22 | + | ||
23 | +} |
1 | -package com.yoho.search.service.scorer.impl; | ||
2 | - | ||
3 | -import com.yoho.search.base.utils.DateUtil; | ||
4 | -import com.yoho.search.base.utils.ProductIndexEsField; | ||
5 | -import com.yoho.search.models.YohoFilterFunctionBuilders; | ||
6 | -import com.yoho.search.service.scorer.IScorer; | ||
7 | -import org.elasticsearch.index.query.QueryBuilders; | ||
8 | -import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; | ||
9 | - | ||
10 | -import java.util.Date; | ||
11 | - | ||
12 | -public class NewProductScorer implements IScorer { | ||
13 | - | ||
14 | - private static final float NEW_PRODUCT_WEIGHT = 1.05f;// 新品得分 | ||
15 | - private int formFirstShelveTime; | ||
16 | - | ||
17 | - public NewProductScorer(int dateLimit){ | ||
18 | - formFirstShelveTime = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(),-1 * dateLimit)); | ||
19 | - } | ||
20 | - | ||
21 | - | ||
22 | - @Override | ||
23 | - public void addScorer(YohoFilterFunctionBuilders yohoFilterFunctionBuilders) { | ||
24 | - yohoFilterFunctionBuilders.add(QueryBuilders.rangeQuery(ProductIndexEsField.firstShelveTime).from(formFirstShelveTime), ScoreFunctionBuilders.weightFactorFunction(NEW_PRODUCT_WEIGHT)); | ||
25 | - } | ||
26 | - | ||
27 | - public static void main(String[] args) { | ||
28 | - System.out.println( DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(),-1 * 90))); | ||
29 | - } | ||
30 | - | ||
31 | -} |
@@ -19,6 +19,7 @@ import com.yoho.search.service.helper.AggCommonHelper; | @@ -19,6 +19,7 @@ import com.yoho.search.service.helper.AggCommonHelper; | ||
19 | import com.yoho.search.service.helper.SearchCommonHelper; | 19 | import com.yoho.search.service.helper.SearchCommonHelper; |
20 | import com.yoho.search.service.service.IShopListService; | 20 | import com.yoho.search.service.service.IShopListService; |
21 | import org.apache.commons.lang.StringUtils; | 21 | import org.apache.commons.lang.StringUtils; |
22 | +import org.elasticsearch.common.lucene.search.function.CombineFunction; | ||
22 | import org.elasticsearch.index.query.BoolQueryBuilder; | 23 | import org.elasticsearch.index.query.BoolQueryBuilder; |
23 | import org.elasticsearch.index.query.MultiMatchQueryBuilder; | 24 | import org.elasticsearch.index.query.MultiMatchQueryBuilder; |
24 | import org.elasticsearch.index.query.Operator; | 25 | import org.elasticsearch.index.query.Operator; |
@@ -76,8 +77,10 @@ public class ShopListServiceImpl implements IShopListService { | @@ -76,8 +77,10 @@ public class ShopListServiceImpl implements IShopListService { | ||
76 | queryBuilder.minimumShouldMatch("100%"); | 77 | queryBuilder.minimumShouldMatch("100%"); |
77 | // 2.1 全球购得分减半 | 78 | // 2.1 全球购得分减半 |
78 | FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[1]; | 79 | FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[1]; |
79 | - filterFunctionBuilders[0] = new FilterFunctionBuilder(QueryBuilders.termQuery("isGlobal", "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f)); | 80 | + filterFunctionBuilders[0] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f)); |
81 | + filterFunctionBuilders[1] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f)); | ||
80 | FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders); | 82 | FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders); |
83 | + functionScoreQueryBuilder.boostMode(CombineFunction.MULTIPLY); | ||
81 | searchParam.setQuery(functionScoreQueryBuilder); | 84 | searchParam.setQuery(functionScoreQueryBuilder); |
82 | 85 | ||
83 | // 3、构建filter | 86 | // 3、构建filter |
-
Please register or login to post a comment