Hello,

I use the code below to get the term frequency for the term searched for by 
the user. However, if the query consists of more than one word (separated by 
space), or if it consists of a phrase within quotes, the term frequency 
equals zero with this code. How can I get the term frequencies for all the 
words in a query?

By the way, I have tried using TermFrequencyVector, but I suspect there is a 
smarter way to do it in this case...

Best regards,

Erik



public void handleFreq(String searchstring){
  NutchBean bean = new NutchBean();
  Query query = Query.parse(searchstring);
  Hits hits = bean.search(query, 100);

  for(int i = 0; i < hits.getLength(); i++) {
     Hit hit = hits.getHit(i);
     int docno = hit.getIndexDocNo();
     FSDirectory dir = FSDirectory.getDirectory("C:/crawl/index", false);
     IndexReader reader = IndexReader.open(dir);

     TermDocs td = reader.termDocs(new Term("content", searchstring));
     int freq=0;
     while (td.next()) {
        if (td.doc() == docno) {
           freq = td.freq();
           ... do something ...
        }
     }
  }
}

_________________________________________________________________
Hur blir vädret till helgen? http://www.msn.se/weather/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nutch-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nutch-general

Reply via email to