|
@@ -22,13 +22,9 @@ import org.springframework.data.elasticsearch.core.SearchHits;
|
|
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
|
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
|
|
import org.springframework.data.elasticsearch.core.query.Query;
|
|
import org.springframework.data.elasticsearch.core.query.Query;
|
|
|
-import org.springframework.lang.Nullable;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,8 +47,27 @@ public class QuestionService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Page<Question> find(String stem, List<String> tags, List<QuestionType> types, List<String> keyPoints,
|
|
public Page<Question> find(String stem, List<String> tags, List<QuestionType> types, List<String> keyPoints,
|
|
|
- List<Integer> weight, List<String> knowledgeIds, Pageable pageable) {
|
|
|
|
|
- return completeQuery(stem, tags, types, keyPoints, weight, knowledgeIds, pageable);
|
|
|
|
|
|
|
+ List<Integer> weights, List<String> knowledgeIds, Pageable pageable) {
|
|
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(stem)) {
|
|
|
|
|
+ criteria = criteria.and("stem").matches(stem);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(tags)) {
|
|
|
|
|
+ criteria = criteria.and("tags").matchesAll(String.join(",", tags));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(knowledgeIds)) {
|
|
|
|
|
+ criteria = criteria.and("knowledge_id").matchesAll(String.join(",", knowledgeIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(keyPoints)) {
|
|
|
|
|
+ criteria = criteria.and("key_points").matchesAll(String.join(",", keyPoints));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(weights)) {
|
|
|
|
|
+ criteria = criteria.and("weight").in(weights);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!EmptyCheck.instance.isEmpty(types)) {
|
|
|
|
|
+ criteria = criteria.and("type").in(types.stream().map(QuestionType::getName).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return findQuestionByCriteria(pageable, criteria);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Iterable<Question> findAllById(Iterable<String> ids) {
|
|
public Iterable<Question> findAllById(Iterable<String> ids) {
|
|
@@ -74,41 +89,16 @@ public class QuestionService {
|
|
|
questionRepository.deleteById(id);
|
|
questionRepository.deleteById(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Page<Question> completeQuery(@Nullable String stem, @Nullable List<String> tags,
|
|
|
|
|
- List<QuestionType> types, @Nullable List<String> keyPoints, List<Integer> weights,
|
|
|
|
|
- @Nullable List<String> knowledgeId, Pageable pageable) {
|
|
|
|
|
- Criteria criteria = new Criteria();
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(stem)) {
|
|
|
|
|
- criteria = criteria.and("stem").matches(stem);
|
|
|
|
|
- }
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(tags)) {
|
|
|
|
|
- criteria = criteria.and("tags").matchesAll(String.join(",", tags));
|
|
|
|
|
- }
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(knowledgeId)) {
|
|
|
|
|
- criteria = criteria.and("knowledge_id").matchesAll(String.join(",", knowledgeId));
|
|
|
|
|
- }
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(keyPoints)) {
|
|
|
|
|
- criteria = criteria.and("key_points").matchesAll(String.join(",", keyPoints));
|
|
|
|
|
- }
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(weights)) {
|
|
|
|
|
- criteria = criteria.and("weight").in(weights);
|
|
|
|
|
- }
|
|
|
|
|
- if (!EmptyCheck.instance.isEmpty(types)) {
|
|
|
|
|
- criteria = criteria.and("type").in(types.stream().map(QuestionType::getName).collect(Collectors.toList()));
|
|
|
|
|
- }
|
|
|
|
|
- return getQuestions(pageable, criteria);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public Page<Question> findUncheckedQuestion(QuestionState state, Pageable pageable) {
|
|
public Page<Question> findUncheckedQuestion(QuestionState state, Pageable pageable) {
|
|
|
Criteria criteria = new Criteria();
|
|
Criteria criteria = new Criteria();
|
|
|
if (!EmptyCheck.instance.isEmpty(state.getName())) {
|
|
if (!EmptyCheck.instance.isEmpty(state.getName())) {
|
|
|
criteria = criteria.and("state").matches(state);
|
|
criteria = criteria.and("state").matches(state);
|
|
|
}
|
|
}
|
|
|
- return getQuestions(pageable, criteria);
|
|
|
|
|
|
|
+ return findQuestionByCriteria(pageable, criteria);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@NotNull
|
|
@NotNull
|
|
|
- private Page<Question> getQuestions(Pageable pageable, Criteria criteria) {
|
|
|
|
|
|
|
+ private Page<Question> findQuestionByCriteria(Pageable pageable, Criteria criteria) {
|
|
|
Query query = new CriteriaQuery(criteria);
|
|
Query query = new CriteriaQuery(criteria);
|
|
|
Sort nextSort = Sort.by(pageable.getSort()
|
|
Sort nextSort = Sort.by(pageable.getSort()
|
|
|
.map(order -> "id".equals(order.getProperty())
|
|
.map(order -> "id".equals(order.getProperty())
|
|
@@ -123,6 +113,12 @@ public class QuestionService {
|
|
|
return new PageImpl<>(questions, pageable, questionSearchHits.getTotalHits());
|
|
return new PageImpl<>(questions, pageable, questionSearchHits.getTotalHits());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ List<Question> findByKnowledgeId(String knowledgeId) {
|
|
|
|
|
+ List<String> knowledgeIds = new ArrayList<>();
|
|
|
|
|
+ knowledgeIds.add(knowledgeId);
|
|
|
|
|
+ return this.find(null, null, null, knowledgeIds, null, null, PageRequest.of(0, 1000)).getContent();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 根据题干和答案生成答案解析
|
|
* 根据题干和答案生成答案解析
|
|
|
*
|
|
*
|