Mike
默认域包含mike
Mike john
Mike OR john
默认域包含mike或者john
+mike +address:zhaotong
Mike AND address:zhaotong
默认域即使mike并且address是zhaotong
id :2
Id域为2
Address:Kunming –desc:she
Address:Kunming AND NOT desc:she
Address是kunming并且desc不是she
(mike OR john) AND address:zhaotong
默认域是mike或者john 并且address是zhaotong
Desc: “she like”
Desc域是she like
desc:”happy girl”~5
查找happy和girl之间距离小于5的文档
J*
默认域是j开头
Johe~
模糊搜索johe
Id:[“1” TO “3”]
Id从1到3
//1、创建QueryParser对象,默认搜索域为content
QueryParser parser = new QueryParser(Version.LUCENE_35, "content", new StandardAnalyzer(Version.LUCENE_35));
//改变空格的默认操作符,以下可以改成AND
//parser.setDefaultOperator(Operator.AND);
//开启第一个字符的通配符匹配,默认关闭因为效率不高
parser.setAllowLeadingWildcard(true);
//搜索content中包含有like的
Query query = parser.parse("like");
//有basketball或者football的,空格默认就是OR
query = parser.parse("basketball football");
//改变搜索域为name为mike
//query = parser.parse("content:like");
//同样可以使用*和?来进行通配符匹配
query = parser.parse("name:j*");
//通配符默认不能放在首位
query = parser.parse("email:*@itat.org");
//匹配name中没有mike但是content中必须有football的,+和-要放置到域说明前面
query = parser.parse("- name:mike + like");
//匹配一个区间,注意:TO必须是大写
query = parser.parse("id:[1 TO 6]");
//闭区间匹配只会匹配到2
query = parser.parse("id:{1 TO 3}");
//完全匹配I Like Football的
query = parser.parse("\"I like football\"");
//匹配I 和football之间有一个单词距离的
query = parser.parse("\"I football\"~1");
//模糊查询
query = parser.parse("name:make~");
//没有办法匹配数字范围(自己扩展Parser)
query = parser.parse("attach:[2 TO 10]");