You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@nutch.apache.org by Erik J <sw...@hotmail.com> on 2006/10/10 15:53:07 UTC
term frequencies for multiple term query
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/