开发者

How to read a Lucene index?

开发者 https://www.devze.com 2022-12-21 10:31 出处:网络
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 L开发者_如何学运维ucene engine, it was someone else in the team, now

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 L开发者_如何学运维ucene engine, it was someone else in the team, now I just want to read its index. Do you how to do that in Java?


Not sure what you mean by "reading" an Index:

  1. If you want to query it you can use IndexSearcher class.

  2. IndexReader allows you to open the index in read mode.

If you want to view the contents of the index, you can use Luke


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();


what you need to look for is how to use IndexReader class, the .terms() method will give you back all the terms in the index.


Just do this:

File indexDirectory = new File("YourIndexLocation");
IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
return reader.maxDoc(); //return total docs in index
0

精彩评论

暂无评论...
验证码 换一张
取 消