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