|
@@ -28,7 +28,8 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
|
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
|
|
|
|
@@ -82,6 +83,33 @@ public class QAProblemService extends ServiceImpl<QAProblemMapper,QAProblem> imp
|
|
|
//return qaProblemEsRepository.search(sourceBuilder.query(),pageable);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<String> think(String keyword) {
|
|
|
+ boolean isChinese = keyword.getBytes().length != keyword.length();
|
|
|
+ BoolQueryBuilder queryBuilder = boolQuery().must(termQuery("state", 1));
|
|
|
+ if(isChinese) {
|
|
|
+ queryBuilder = queryBuilder.must(boolQuery().
|
|
|
+ should(matchQuery("tags", keyword).boost(10)).
|
|
|
+ should(matchQuery("title", keyword).boost(5))
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ queryBuilder = queryBuilder.must(boolQuery().
|
|
|
+ should(matchQuery("tags.pinyin", keyword).boost(10)).
|
|
|
+ should(matchQuery("title.pinyin", keyword).boost(5))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ Page<QAProblemEs> page = qaProblemEsRepository.search(queryBuilder, PageRequest.of(0,10));
|
|
|
+ Set<String> set = page.getContent().stream()
|
|
|
+ .map(i -> i.getTags() == null ? i.getTitle() : i.getTags())
|
|
|
+ .flatMap(i -> Arrays.stream(i.split("\\|")))
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ List<String> res = new ArrayList<>(set);
|
|
|
+ res = res.stream()
|
|
|
+ .sorted(Comparator.comparingInt(String::length))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Tuple2<Integer,String> addQAProblemEs(Long id) {
|
|
|
var list = getWrappedProblem(id,0,1);
|