orezvani
orezvani

Reputation: 3765

Frequency of a Term in a Document

I have indexed a set of text files by lucene. Also, I have stored TermVectors. But I want to know the frequency of some terms in some documents in O(1). Is it possible?

I mean, is there a function(Term term, Integer docNum) that returns the frequency of term in document docNum ?

Upvotes: 0

Views: 242

Answers (1)

Marko Topolnik
Marko Topolnik

Reputation: 200138

There is no ready-made function, you'll have to write some code. First use IndexReader.termDocs(Term). That will give you a TermDocs instance which is, typically of Lucene, a Cursor-like object. Now call TermDocs.skipTo(int), then TermDocs.next(), then TermDocs.freq(). If you are sure at the outset that your document contains your term, this is it; otherwise check after each step whether you can proceed. The Javadocs are well-written for each step involved.

Upvotes: 1

Related Questions