Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
55454d43
提交
55454d43
authored
3月 28, 2025
作者:
yanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
专题检索逻辑优化
上级
4d588d16
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
7 行删除
+50
-7
EsService.java
src/main/java/com/zzsn/event/es/EsService.java
+16
-5
EsIndexUtil.java
src/main/java/com/zzsn/event/util/EsIndexUtil.java
+34
-2
没有找到文件。
src/main/java/com/zzsn/event/es/EsService.java
浏览文件 @
55454d43
...
@@ -17,6 +17,7 @@ import com.zzsn.event.entity.SubjectStatisticInfo;
...
@@ -17,6 +17,7 @@ import com.zzsn.event.entity.SubjectStatisticInfo;
import
com.zzsn.event.service.*
;
import
com.zzsn.event.service.*
;
import
com.zzsn.event.util.DateUtil
;
import
com.zzsn.event.util.DateUtil
;
import
com.zzsn.event.util.EsDateUtil
;
import
com.zzsn.event.util.EsDateUtil
;
import
com.zzsn.event.util.EsIndexUtil
;
import
com.zzsn.event.util.tree.Node
;
import
com.zzsn.event.util.tree.Node
;
import
com.zzsn.event.vo.*
;
import
com.zzsn.event.vo.*
;
import
com.zzsn.event.vo.es.DisplayInfo
;
import
com.zzsn.event.vo.es.DisplayInfo
;
...
@@ -738,7 +739,9 @@ public class EsService {
...
@@ -738,7 +739,9 @@ public class EsService {
* @date 2024/5/6
* @date 2024/5/6
*/
*/
public
IPage
<
SpecialInformation
>
pageListByCondition
(
InfoDataSearchCondition
searchCondition
,
List
<
String
>
subjectIdList
)
throws
IOException
{
public
IPage
<
SpecialInformation
>
pageListByCondition
(
InfoDataSearchCondition
searchCondition
,
List
<
String
>
subjectIdList
)
throws
IOException
{
SearchRequest
searchRequest
=
new
SearchRequest
(
Constants
.
SUBJECT_INDEX
);
Subject
byId
=
subjectService
.
getById
(
searchCondition
.
getSubjectId
());
String
[]
indexs
=
EsIndexUtil
.
getIndexIntervalYear
(
Constants
.
SUBJECT_INDEX
,
byId
.
getCreateTime
());
SearchRequest
searchRequest
=
new
SearchRequest
(
indexs
);
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
//默认最大数量是10000,设置为true后,显示准确数量
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder
.
trackTotalHits
(
true
);
searchSourceBuilder
.
trackTotalHits
(
true
);
...
@@ -819,7 +822,9 @@ public class EsService {
...
@@ -819,7 +822,9 @@ public class EsService {
List
<
String
>
list
=
new
ArrayList
<>();
List
<
String
>
list
=
new
ArrayList
<>();
List
<
String
>
idList
=
Arrays
.
asList
(
ids
.
split
(
","
));
List
<
String
>
idList
=
Arrays
.
asList
(
ids
.
split
(
","
));
List
<
String
>
beInStorageList
=
idList
.
stream
().
map
(
uniqueCode
->
subjectId
+
uniqueCode
).
collect
(
Collectors
.
toList
());
List
<
String
>
beInStorageList
=
idList
.
stream
().
map
(
uniqueCode
->
subjectId
+
uniqueCode
).
collect
(
Collectors
.
toList
());
SearchRequest
searchRequest
=
new
SearchRequest
(
Constants
.
SUBJECT_INDEX
);
Subject
byId
=
subjectService
.
getById
(
subjectId
);
String
[]
indexs
=
EsIndexUtil
.
getIndexIntervalYear
(
Constants
.
SUBJECT_INDEX
,
byId
.
getCreateTime
());
SearchRequest
searchRequest
=
new
SearchRequest
(
indexs
);
//创建查询对象
//创建查询对象
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
boolQuery
.
must
(
QueryBuilders
.
termsQuery
(
"id"
,
beInStorageList
));
boolQuery
.
must
(
QueryBuilders
.
termsQuery
(
"id"
,
beInStorageList
));
...
@@ -1066,7 +1071,9 @@ public class EsService {
...
@@ -1066,7 +1071,9 @@ public class EsService {
//调用判重接口
//调用判重接口
public
boolean
duplicationByTitleOrSourceAddress
(
DisplayInfo
displayInfo
)
{
public
boolean
duplicationByTitleOrSourceAddress
(
DisplayInfo
displayInfo
)
{
SearchRequest
searchRequest
=
new
SearchRequest
(
Constants
.
SUBJECT_INDEX
);
Subject
byId
=
subjectService
.
getById
(
displayInfo
.
getSubjectId
());
String
[]
indexs
=
EsIndexUtil
.
getIndexIntervalYear
(
Constants
.
SUBJECT_INDEX
,
byId
.
getCreateTime
());
SearchRequest
searchRequest
=
new
SearchRequest
(
indexs
);
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
shouldBoolQuery
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
shouldBoolQuery
=
QueryBuilders
.
boolQuery
();
...
@@ -1106,7 +1113,9 @@ public class EsService {
...
@@ -1106,7 +1113,9 @@ public class EsService {
if
(
CollectionUtils
.
isNotEmpty
(
ids
))
{
if
(
CollectionUtils
.
isNotEmpty
(
ids
))
{
count
=
ids
.
size
();
count
=
ids
.
size
();
}
else
{
}
else
{
SearchRequest
searchRequest
=
new
SearchRequest
(
Constants
.
SUBJECT_INDEX
);
Subject
byId
=
subjectService
.
getById
(
searchCondition
.
getSubjectId
());
String
[]
indexs
=
EsIndexUtil
.
getIndexIntervalYear
(
Constants
.
SUBJECT_INDEX
,
byId
.
getCreateTime
());
SearchRequest
searchRequest
=
new
SearchRequest
(
indexs
);
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
//默认最大数量是10000,设置为true后,显示准确数量
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder
.
trackTotalHits
(
true
);
searchSourceBuilder
.
trackTotalHits
(
true
);
...
@@ -1149,7 +1158,9 @@ public class EsService {
...
@@ -1149,7 +1158,9 @@ public class EsService {
* @param searchCondition 查询条件封装
* @param searchCondition 查询条件封装
*/
*/
public
List
<
SpecialInformation
>
informationList
(
InfoDataSearchCondition
searchCondition
)
{
public
List
<
SpecialInformation
>
informationList
(
InfoDataSearchCondition
searchCondition
)
{
SearchRequest
searchRequest
=
new
SearchRequest
(
Constants
.
SUBJECT_INDEX
);
Subject
byId
=
subjectService
.
getById
(
searchCondition
.
getSubjectId
());
String
[]
indexs
=
EsIndexUtil
.
getIndexIntervalYear
(
Constants
.
SUBJECT_INDEX
,
byId
.
getCreateTime
());
SearchRequest
searchRequest
=
new
SearchRequest
(
indexs
);
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
String
column
=
searchCondition
.
getColumn
();
String
column
=
searchCondition
.
getColumn
();
String
order
=
searchCondition
.
getOrder
();
String
order
=
searchCondition
.
getOrder
();
...
...
src/main/java/com/zzsn/event/util/EsIndexUtil.java
浏览文件 @
55454d43
package
com
.
zzsn
.
event
.
util
;
package
com
.
zzsn
.
event
.
util
;
import
cn.hutool.core.date.DateUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -41,6 +43,14 @@ public class EsIndexUtil {
...
@@ -41,6 +43,14 @@ public class EsIndexUtil {
return
indexs
;
return
indexs
;
}
}
/**
* 根据索引名称获取带有上年的索引名称 subjectdatabase --> subjectdatabase_2023
* @param index
* @return
*/
public
static
String
getPreIndexYear
(
String
index
){
return
index
+
"_"
+
(
LocalDateTime
.
now
().
getYear
()
-
1
);
}
/**
/**
* 获取两个时间之间的所有年份
* 获取两个时间之间的所有年份
...
@@ -78,11 +88,34 @@ public class EsIndexUtil {
...
@@ -78,11 +88,34 @@ public class EsIndexUtil {
* 获取两个时间之间的所有年份
* 获取两个时间之间的所有年份
* 并返回数组
* 并返回数组
* @param startDate 搜索范围开始年份
* @param startDate 搜索范围开始年份
* @return
*/
public
static
String
[]
getIndexIntervalYear
(
String
index
,
Date
startDate
){
if
(
startDate
==
null
){
return
new
String
[]{
index
};
}
return
getIndexIntervalYearStr
(
index
,
DateUtil
.
formatDate
(
startDate
));
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startDate 搜索范围开始年份
* @return
*/
public
static
String
[]
getIndexIntervalYearStr
(
String
index
,
String
startDate
){
return
getIndexIntervalYear
(
index
,
startDate
,
null
);
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startDate 搜索范围开始年份
* @param endDate 搜索范围结束年份
* @param endDate 搜索范围结束年份
* @return
* @return
*/
*/
public
static
String
[]
getIndexIntervalYear
(
String
index
,
String
startDate
,
String
endDate
){
public
static
String
[]
getIndexIntervalYear
(
String
index
,
String
startDate
,
String
endDate
){
if
(
StringUtils
.
isEmpty
(
startDate
)
&&
StringUtils
.
isEmpty
(
endDate
)){
return
new
String
[]{
index
};
}
Integer
startYear
;
Integer
startYear
;
Integer
endYear
;
Integer
endYear
;
if
(
StringUtils
.
isNotBlank
(
startDate
))
{
if
(
StringUtils
.
isNotBlank
(
startDate
))
{
...
@@ -108,5 +141,4 @@ public class EsIndexUtil {
...
@@ -108,5 +141,4 @@ public class EsIndexUtil {
String
[]
indexs
=
getIndexIntervalYear
(
index
,
startYear
,
endYear
);
String
[]
indexs
=
getIndexIntervalYear
(
index
,
startYear
,
endYear
);
return
indexs
;
return
indexs
;
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论