Browse Source

fix: 修复lucene对特定字段索引不分词查询语法

master
JiaoLM 2 years ago
parent
commit
418eb6f5c1
  1. 14
      acs/nladmin-system/src/main/java/org/nl/modules/lucence/common/Searcher.java

14
acs/nladmin-system/src/main/java/org/nl/modules/lucence/common/Searcher.java

@ -68,15 +68,21 @@ public class Searcher {
} }
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true); TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true);
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST); booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
if (whereJson.get("device_code") != null){
Query termQuery = new TermQuery(new Term("device_code", (String) whereJson.get("device_code")));
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
}
//日志类型 //日志类型
if (whereJson.get("blurry") != null) queryString += "+fieldContent:"+(String) whereJson.get("blurry"); // if (whereJson.get("blurry") != null) queryString += "fieldContent:"+(String) whereJson.get("blurry");
if (whereJson.get("device_code") != null) queryString += " +device_code:"+(String) whereJson.get("device_code"); if (whereJson.get("blurry") != null) queryString = (String) whereJson.get("blurry");
if (whereJson.get("device_code") == null && whereJson.get("blurry") == null) { // if (whereJson.get("device_code") != null) queryString += " +device_code:"+(String) whereJson.get("device_code");
if (whereJson.get("blurry") == null) {
WildcardQuery query=new WildcardQuery(new Term("fieldContent","*")); WildcardQuery query=new WildcardQuery(new Term("fieldContent","*"));
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST); booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
docs = searcher.search(booleanQueryBuilder.build(), end,sort); docs = searcher.search(booleanQueryBuilder.build(), end,sort);
}else { }else {
Query query = queryParser.parse(queryString); Query query = queryParser.parse((String) whereJson.get("blurry"));
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST); booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
docs = searcher.search(booleanQueryBuilder.build(), end,sort); docs = searcher.search(booleanQueryBuilder.build(), end,sort);
} }

Loading…
Cancel
Save