lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sethu_424 <sethu....@gmail.com>
Subject Re: Getting DF & IDF
Date Wed, 26 May 2010 14:15:31 GMT

Hi,
I am not sure if you are still searching the answer for your question. If
so, then please read on...

You can get the DF & IDF for each of the query terms in the query as below..

IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexDir)),
true); 
	
//Create a FilterIndexReader to invoke the abstract methods
FilterIndexReader filterIndexReader = new FilterIndexReader(reader);
	
//Number of documents in the index
int numDocs = filterIndexReader.numDocs();
	
//Iterate over each of the query words
for(String queryWord : queryWords){
   Term term = new Term(searchField, queryWord.toLowerCase());
    
   int docFreq = 0;
	try {
              docFreq = filterIndexReader.docFreq(term);
	} catch (IOException e) {
               logger.log(Level.SEVERE, null, e);
	}
					   
	//Calculate IDF
	double idf = 0.0;
	if(docFreq > 0){
	      idf = Math.log10((double) numDocs / docFreq);
	}
	 
   System.out.println(queryWord + "\tDF -" + docFreq + "\tIDF -" + idf);
}

-- 
View this message in context: http://lucene.472066.n3.nabble.com/Getting-DF-IDF-tp547386p844962.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message