I have an index with 2 docs at the moment (will add some more after everything will work ok).
I try to calculate the df
for a specific term but I get all the time the total number of docs in the index as a result.for debug purpose I entered a unique string in one doc so the result of the df should be 1. but, it returns 2. at the end of the process I'll need a tf/idf
score for every word in the index.
I've tried the following code:
public void calcDF (String term) throws IOException
{
//open the index file
Directory dir = FSDirectory.open(new File("d:/index"));
//create a reader
IndexReader ir = IndexReader.open(dir);
//for debug
System.out.println("num of docs in index : " + ir.maxDoc());
Term t = new Term("content",term);
int df = ir.docFreq(t);
}
Tried also with IndexSearcher searcher = new IndexSearcher(ir);
instead of indexReader
but no luck.
P.S: I'm using lucene 3.5