//省略重复部分
/**
* @author: baifan
* @date: 2021/6/15
*/
public class TermQueryTest {
public static void main(String[] args)
throws ParseException, IOException {
Term term = new Term("title", "美国");
Path indexPath = Paths.get("indexdir");
Directory dir = FSDirectory.open(indexPath);
IndexReader reader = DirectoryReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);
//使用智能分词
Analyzer analyzer = new IKAnalyzer6x(true);
Query query = new TermQuery(term);
System.out.println("Query:" + query.toString());
// 返回前10条
//省略重复部分
}
}
运行结果:
Query:title:美国
DocID:2
id:3
title:XXXXXXXXXXXXXXXXXXXX
文档评分:0.4893146
DocID:0
id:1
title:XXXXXXXXXXXXXXXXXX
文档评分:0.40224567
Process finished with exit code 0