|
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
|
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
|
@@ -54,10 +55,10 @@ public class QAProblemService extends ServiceImpl<QAProblemMapper,QAProblem> imp
|
|
|
BoolQueryBuilder queryBuilder = boolQuery().
|
|
|
must(termQuery("state", 1)).
|
|
|
must(boolQuery().
|
|
|
- should(matchQuery("tags", keyword)).
|
|
|
- should(matchQuery("tags.pinyin", keyword)).
|
|
|
- should(matchQuery("title", keyword)).
|
|
|
- should(matchQuery("title.pinyin", keyword)).
|
|
|
+ should(matchQuery("tags", keyword).boost(100)).
|
|
|
+ should(matchQuery("tags.pinyin", keyword).boost(90)).
|
|
|
+ should(matchQuery("title", keyword).boost(10)).
|
|
|
+ should(matchQuery("title.pinyin", keyword).boost(9)).
|
|
|
should(matchQuery("describe", keyword)).
|
|
|
should(matchQuery("describe.pinyin", keyword))
|
|
|
);
|
|
@@ -66,7 +67,7 @@ public class QAProblemService extends ServiceImpl<QAProblemMapper,QAProblem> imp
|
|
|
try {
|
|
|
SearchResponse response = elasticsearchRestTemplate.getClient().search(request, RequestOptions.DEFAULT);
|
|
|
Float maxScore = response.getHits().getMaxScore();
|
|
|
- Double mustMinScore = (maxScore * 0.5);
|
|
|
+ Double mustMinScore = (maxScore * 0.0);
|
|
|
|
|
|
var secondSearch = new NativeSearchQuery(queryBuilder);
|
|
|
secondSearch.setMinScore(mustMinScore.floatValue());
|