WildcardQuery即通配符查询,即使用通配符来模糊查询,常见的通配符有?,*,-等等,通配符不知道怎么使用的自己Google学习下吧。照例还是先阅读官方的API文档:
特别要注意的Note后面的话,提醒我们注意,WildcardQuery查询是很慢的,因为它需要遍历很多的Term,为了避免极慢的查询速度,请不要使用以星号开头的通配符进行查询。
除了官方给的那点提醒以外,我也要提醒大家一点,WildcardQuery对于用户输入的查询关键字是大小写敏感的,请不要使用大写形式,因为索引中的Term都是小写形式的,这个大家都知道的,特此提醒。
WildcardQuery构造函数除了需要一个Term对象以外,还有一个参数需要设置maxDeterminizedStates,源码注释里是这样解释的:
/** * Constructs a query for terms matching <code>term</code>. * @param maxDeterminizedStates maximum number of states in the resulting * automata. If the automata would need more than this many states * TooComplextToDeterminizeException is thrown. Higher number require more * space but can process more complex automata. */ public WildcardQuery(Term term, int maxDeterminizedStates) { super(term, toAutomaton(term), maxDeterminizedStates); }
其实就是设置根据通配符支持最大能支持有多少Term情况,Term越多占的硬盘空间越大,但查询也更精确。这个值默认源码里给定的是10000,默认即可。
其他也没什么好说的,WildcardQuery使用难度也不大,照样贴一个使用示例吧:
String directoryPath = "D:/lucenedir"; String fieldName = "contents"; String queryString = "*recursive*"; Query query = new WildcardQuery(new Term(fieldName,queryString));
示例代码的意图就是查询索引文档中包含recursive这个单词的,OK,打完收工了,此时此刻2015-03-24 22:26,该睡觉了。预计接下来要说说的就是SpanQuery了。
如果你还有什么问题请加我Q-Q:7-3-6-0-3-1-3-0-5,
或者加裙
一起交流学习!
相关推荐
lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习...
NULL 博文链接:https://iamyida.iteye.com/blog/2203743
NULL 博文链接:https://iamyida.iteye.com/blog/2199848
NULL 博文链接:https://iamyida.iteye.com/blog/2207080
NULL 博文链接:https://iamyida.iteye.com/blog/2202111
Lucene的的学习资料及案例,包括一个lucene的学习资料总结。供大家学习使用,也有本人写的一个小案例。
NULL 博文链接:https://iamyida.iteye.com/blog/2201372
NULL 博文链接:https://iamyida.iteye.com/blog/2205114
NULL 博文链接:https://iamyida.iteye.com/blog/2197839
NULL 博文链接:https://iamyida.iteye.com/blog/2202651
NULL 博文链接:https://iamyida.iteye.com/blog/2203575
(1) 使用writer删除 5 (2) 使用reader删除 5 (3) 恢复删除 5 (4) 彻底删除 6 (5) 更新索引 6 (6) 手动优化 6 2.6 索引文件作用 7 第三章 搜索功能 8 3.1 简单搜索 8 (1) 创建IndexReader 8 (2) 创建IndexSearcher 8 ...
NULL 博文链接:https://iamyida.iteye.com/blog/2206107
NULL 博文链接:https://iamyida.iteye.com/blog/2193345
NULL 博文链接:https://iamyida.iteye.com/blog/2199368
Lucene.net学习.docx
NULL 博文链接:https://iamyida.iteye.com/blog/2204455
NULL 博文链接:https://iamyida.iteye.com/blog/2201291
NULL 博文链接:https://iamyida.iteye.com/blog/2196855
NULL 博文链接:https://iamyida.iteye.com/blog/2201196