mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 09:26:48 +08:00
zcwy-dev
This commit is contained in:
@@ -2,6 +2,8 @@ package com.xboe.module.course.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 课程的全文检索索引
|
||||
*
|
||||
@@ -28,7 +30,6 @@ public class CourseFullText {
|
||||
|
||||
/**10无目录录播课,20 有目录录播课,30:面授课;40学习项目*/
|
||||
private Integer type;
|
||||
|
||||
/**多个时用到*/
|
||||
private String types;
|
||||
|
||||
@@ -118,5 +119,11 @@ public class CourseFullText {
|
||||
* 是否公开0表非公开报名,1表公开报名-字段需新增,按管理端需求增加
|
||||
*/
|
||||
private Integer openEnroll;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* keywords字段分割
|
||||
*/
|
||||
private List<String> keywordsList;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@ package com.xboe.module.elasticsearc;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -33,10 +31,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.RangeQueryBuilder;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
@@ -410,6 +405,8 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
BoolQueryBuilder keywordQuery = QueryBuilders.boolQuery();
|
||||
keywordQuery.should(QueryBuilders.wildcardQuery("name", "*"+words+"*").boost(9f));
|
||||
keywordQuery.should(QueryBuilders.wildcardQuery("teacher", "*"+words+"*").boost(7f));
|
||||
keywordQuery.should(QueryBuilders.queryStringQuery("*" + words + "*").field("keywords"));
|
||||
keywordQuery.should(QueryBuilders.queryStringQuery(words).field("keywords"));
|
||||
//keywordQuery.should(QueryBuilders.queryStringQuery(words).field("name", 9f));//用此方法无法查询出有转义符的处理
|
||||
//keywordQuery.should(QueryBuilders.queryStringQuery(words).field("teacher", 8f));
|
||||
|
||||
@@ -426,8 +423,8 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
//// //其它是教师,教师也是 like查询, 它只是2位权重
|
||||
//// boolQuery.should(QueryBuilders.queryStringQuery(params.getKeywords()).field("teacher", 5f));
|
||||
//// //关键词查询
|
||||
//// boolQuery.should(QueryBuilders.queryStringQuery(params.getKeywords()).field("keywords", 3f));
|
||||
////
|
||||
// boolQuery.should(QueryBuilders.queryStringQuery(params.getKeywords()).field("keywords", 10f));
|
||||
////
|
||||
//// //boolQuery.should(QueryBuilders.fuzzyQuery("keywords",params.getKeywords()).boost(3f));
|
||||
//// //分词查询,权重是1,默念
|
||||
//// boolQuery.should(QueryBuilders.multiMatchQuery(params.getKeywords(),"summary"));
|
||||
@@ -613,7 +610,7 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
}
|
||||
|
||||
//排序
|
||||
if(StringUtils.isBlank(paras.getKeywords())) {
|
||||
if(StringUtils.isBlank(paras.getKeywords()) && paras.getOrderType()!=3) {
|
||||
sourceBuilder.sort("isTop",SortOrder.DESC);
|
||||
//sourceBuilder.sort("topTime",SortOrder.DESC);
|
||||
}
|
||||
@@ -623,6 +620,9 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
}else if(paras.getOrderType()==2) {
|
||||
sourceBuilder.sort("studies",SortOrder.DESC);
|
||||
}
|
||||
}else if (paras.getOrderType()==3){
|
||||
sourceBuilder.sort("score",SortOrder.DESC);
|
||||
}
|
||||
}
|
||||
|
||||
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
|
||||
@@ -637,10 +637,10 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
HighlightBuilder.Field nameHighlight=new HighlightBuilder.Field("name");
|
||||
HighlightBuilder.Field summaryHighlight=new HighlightBuilder.Field("summary");
|
||||
HighlightBuilder.Field teacherHighlight=new HighlightBuilder.Field("teacher");
|
||||
HighlightBuilder.Field keywordsHighlight=new HighlightBuilder.Field("keywords");
|
||||
// HighlightBuilder.Field keywordsHighlight=new HighlightBuilder.Field("keywords");
|
||||
highlightBuilder.field(nameHighlight);
|
||||
highlightBuilder.field(teacherHighlight);
|
||||
highlightBuilder.field(keywordsHighlight);
|
||||
// highlightBuilder.field(keywordsHighlight);
|
||||
highlightBuilder.field(summaryHighlight);
|
||||
|
||||
|
||||
@@ -663,7 +663,7 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
HighlightField name = highlightFields.get("name");
|
||||
HighlightField summary = highlightFields.get("summary");
|
||||
HighlightField teacher = highlightFields.get("teacher");
|
||||
HighlightField keywords = highlightFields.get("keywords");
|
||||
// HighlightField keywords = highlightFields.get("keywords");
|
||||
String sourceAsString = hit.getSourceAsString();
|
||||
try {
|
||||
CourseFullText cft =mapper.readValue(sourceAsString, CourseFullText.class);
|
||||
@@ -695,15 +695,15 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
}
|
||||
cft.setTeacher(fmtStr.toString());
|
||||
}
|
||||
|
||||
if(keywords!= null){
|
||||
|
||||
/*if(keywords!= null){
|
||||
Text[] fragments = keywords.fragments();
|
||||
StringBuffer fmtStr = new StringBuffer("");
|
||||
for (Text fragment : fragments) {
|
||||
fmtStr.append(fragment);
|
||||
}
|
||||
cft.setKeywords(fmtStr.toString());
|
||||
}
|
||||
}*/
|
||||
list.add(cft);
|
||||
}catch(Exception ee) {
|
||||
log.error("转化json到对应失败");
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<module>boe-module-es</module>
|
||||
<module>boe-module-idconfig</module>
|
||||
<module>boe-module-savelog</module>
|
||||
<module>boe-module-scorm</module>
|
||||
</modules>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
Reference in New Issue
Block a user