I just wonder how Lucene can make it,and from the source code I know that it opens and loads the segment files when intializing a searcher with a IndexReader,but Is there any kind person tell me how Lucene calculates the term frequency in a document with special field. Is there any special algorithm? I can not figure it out when reading the explan code on tf ,like:
Explanation tfExplanation = new Explanation();
int d = scorer.advance(doc);
float phraseFreq = (d == doc) ? scorer.currentFreq() : 0.0f;
tfExplanation.setValue(similarity.tf(phraseFreq));
tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");
the Idf>0,but why phraseFreq in the code is 0.0,and I know it is because (d == doc) is false,because the d=Integer.MAX_VALUE,I don't know why and what is the problem.
I have only one document with one field,which is indexed and stored,and the doc which is used in the debug code is 1,like searcher.explan(booleanQuery,1);