lucene的丰富的各种查询(一)
来源:互联网 发布:ps dr3插件for mac 编辑:程序博客网 时间:2024/05/22 00:38
lucene支持十分丰富的查询,这里列写其中一些比较常用的查询的用法。
term查询
queryParser查询
booleanQuery查询
package search;import org.apache.lucene.analysis.standard.StandardAnalyzer;import org.apache.lucene.index.Term;import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.Hits;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.search.TermQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;public class Searcher { public static void termQuery() throws Exception{ Directory directory = FSDirectory.getDirectory("./index", false); IndexSearcher searcher = new IndexSearcher(directory); Term t = new Term("body","document"); Query query = new TermQuery(t); Hits hits = searcher.search(query); System.out.println(hits.length()); } public static void queryParser() throws Exception{ Directory directory = FSDirectory.getDirectory("./index", false); IndexSearcher searcher = new IndexSearcher(directory); Query query = QueryParser.parse("text","body",new StandardAnalyzer()); Hits hits = searcher.search(query); System.out.println(hits.length()); } public static void booleanQuery() throws Exception{ Query parseQuery = QueryParser.parse("text","body",new StandardAnalyzer()); Term t = new Term("body","document"); Query termQuery = new TermQuery(t); BooleanQuery boolQuery = new BooleanQuery(); boolQuery.add(parseQuery,true,false); boolQuery.add(termQuery,true,false); Directory directory = FSDirectory.getDirectory("./index", false); IndexSearcher searcher = new IndexSearcher(directory); Hits hits = searcher.search(boolQuery); System.out.println(hits.length()); } public static void main(String[] args) throws Exception{ termQuery(); queryParser(); booleanQuery(); }}
0 0
- lucene的丰富的各种查询(一)
- lucene的丰富的各种查询(二)
- Lucene的各种查询
- 超级丰富的组件 各种语言
- Lucene的各种query
- 丰富的
- Lucene的查询语法!
- Lucene的组合查询
- Lucene的分页查询
- lucene的查询语法
- Lucene的查询语句
- Lucene的分页查询
- Lucene的组合查询
- lucene(索引的查询)
- JMeter--丰富的函数助手(一)
- CocoaChina上各种开发专题的丰富例子
- Lucene的使用(一)
- 借助case,实现更丰富的分组查询统计
- SQL数据修复,SQL数据库修复,SQL数据库修复软件,SQL数据库恢复,SQL数据库日志恢复软件
- Linux无法连接外网
- 安装mysql5.7
- 最小生成树——Kruskal算法
- 后端程序员也需要理解的HTTP缓存
- lucene的丰富的各种查询(一)
- 一点一点积累的快捷键
- Hibernate Validator
- 静态链表
- My enum is not a class or namespace
- Java并发编程系列之二十一:CountdownLatch
- 获取设备上的调试信息与崩溃日志分析
- CodeForces - 616A Comparing Two Long Integers (模拟)比较两个数大小
- 数组转集合,集合转数组