...
|
...
|
@@ -27,11 +27,13 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; |
|
|
import org.elasticsearch.index.query.Operator;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
|
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
|
|
|
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
|
...
|
...
|
@@ -71,9 +73,9 @@ public class ShopListService { |
|
|
}
|
|
|
queryBuilder.minimumShouldMatch("100%");
|
|
|
// 2.1 全球购得分减半
|
|
|
FunctionScoreQueryBuilder.FilterFunctionBuilder[] filterFunctionBuilders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[2];
|
|
|
filterFunctionBuilders[0] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));
|
|
|
filterFunctionBuilders[1] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f));
|
|
|
FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[2];
|
|
|
filterFunctionBuilders[0] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));
|
|
|
filterFunctionBuilders[1] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f));
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders);
|
|
|
functionScoreQueryBuilder.boostMode(CombineFunction.MULTIPLY);
|
|
|
searchParam.setQuery(functionScoreQueryBuilder);
|
...
|
...
|
@@ -144,10 +146,10 @@ public class ShopListService { |
|
|
* @return
|
|
|
*/
|
|
|
private List<Map<String, Object>> getShopList(final MultiBucketsAggregation aggregation) {
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
List<Map<String, Object>> productSourceList = new ArrayList<Map<String, Object>>();
|
|
|
while (itAgg.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket lt = itAgg.next();
|
|
|
Bucket lt = itAgg.next();
|
|
|
if (lt.getAggregations().getAsMap().containsKey("product")) {
|
|
|
TopHits topHits = lt.getAggregations().get("product");
|
|
|
productSourceList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits));
|
...
|
...
|
|