fix: 日志管理无法使用日期查询
This commit is contained in:
@@ -3,6 +3,7 @@ package org.nl.config.lucene;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
@@ -55,20 +56,16 @@ public class Searcher {
|
||||
|
||||
TopDocs docs = null;
|
||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||
//时间范围查询
|
||||
String startDate = whereJson.getString("begin_time");
|
||||
String endDate = whereJson.getString("end_time");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(1970, 0, 1);
|
||||
if (startDate == null) {
|
||||
startDate = DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
} else {
|
||||
startDate = LuceneIndexWriter.getDate(startDate);
|
||||
}
|
||||
if (endDate == null) {
|
||||
endDate = DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
} else {
|
||||
endDate = LuceneIndexWriter.getDate(endDate);
|
||||
//时间范围查询
|
||||
JSONArray createTime = whereJson.getJSONArray("createTime");
|
||||
String startDate = DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
String endDate = DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
if (createTime != null) {
|
||||
startDate = createTime.getString(0);
|
||||
endDate = createTime.getString(1);
|
||||
}
|
||||
// 字段之间的与或非关系,MUST表示and,MUST_NOT表示not,SHOULD表示or,有几个fields就必须有几个clauses
|
||||
TermRangeQuery termRangeQuery = new TermRangeQuery("timestamp", new BytesRef(startDate),
|
||||
|
||||
Reference in New Issue
Block a user