java 如何读取Lucene索引?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2335329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read a Lucene index?
提问by John Manak
I'm working on a project for which I want to build a tag cloud by reading a Lucene index and pruning it down. I didn't set up the Lucene engine, it was someone else in the team, now I just want to read its index. Do you how to do that in Java?
我正在处理一个项目,我想通过读取 Lucene 索引并对其进行修剪来构建标签云。我没有设置Lucene引擎,是团队中的其他人,现在我只想读取它的索引。你如何在Java中做到这一点?
采纳答案by John Manak
what you need to look for is how to use IndexReaderclass, the .terms()method will give you back all the terms in the index.
您需要寻找的是如何使用IndexReader类,.terms()方法将返回索引中的所有术语。
回答by Mikos
Not sure what you mean by "reading" an Index:
不确定“阅读”索引是什么意思:
If you want to query it you can use IndexSearcher class.
IndexReader allows you to open the index in read mode.
如果你想查询它,你可以使用 IndexSearcher 类。
IndexReader 允许您以读取模式打开索引。
If you want to view the contents of the index, you can use Luke
如果要查看索引的内容,可以使用Luke
回答by Srikar Appalaraju
You do it like this -
你这样做 -
IndexReader r = IndexReader.open( "prdb_index");
int num = r.numDocs();
for ( int i = 0; i < num; i++)
{
if ( ! r.isDeleted( i))
{
Document d = r.document( i);
System.out.println( "d=" +d);
}
}
r.close();
回答by userPS
Just do this:
只需这样做:
File indexDirectory = new File("YourIndexLocation");
IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
return reader.maxDoc(); //return total docs in index

