|
@@ -12,6 +12,8 @@ import org.apache.lucene.analysis.TokenStream;
|
|
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
|
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
|
import org.apache.lucene.document.Document;
|
|
import org.apache.lucene.document.Document;
|
|
import org.apache.lucene.index.Term;
|
|
import org.apache.lucene.index.Term;
|
|
|
|
+import org.apache.lucene.queryparser.classic.ParseException;
|
|
|
|
+import org.apache.lucene.queryparser.classic.QueryParser;
|
|
import org.apache.lucene.search.BooleanClause.Occur;
|
|
import org.apache.lucene.search.BooleanClause.Occur;
|
|
import org.apache.lucene.search.*;
|
|
import org.apache.lucene.search.*;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -170,6 +172,25 @@ public class SearchUtils {
|
|
return new RegexpQuery(new Term(field, ".*" + keyword.toLowerCase() + ".*"));
|
|
return new RegexpQuery(new Term(field, ".*" + keyword.toLowerCase() + ".*"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * 查询值不为空
|
|
|
|
+ *
|
|
|
|
+ * @param field
|
|
|
|
+ * 搜索的域名
|
|
|
|
+ * @return 构造的查询
|
|
|
|
+ */
|
|
|
|
+ public static Query getNotNullQuery(String field){
|
|
|
|
+ if (StringUtils.isEmpty(field)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String query = field + ":[* TO *]";
|
|
|
|
+ try {
|
|
|
|
+ return new QueryParser(null, null).parse(query);
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ throw new IllegalStateException("查询语法错误:" + query);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
* 获取指定表的IndexSearcher对象,若为空,抛出异常
|
|
* 获取指定表的IndexSearcher对象,若为空,抛出异常
|
|
*
|
|
*
|