Sfoglia il codice sorgente

调整参数,去掉最低分限制

Jacky Wong 4 anni fa
parent
commit
d1deb8c9c1

+ 6 - 5
search-service-quiz/src/main/java/com/liangjian/search/service/impl/QAProblemService.java

@@ -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());