开发者

How to calculate the frequency for a special term in a document field?

开发者 https://www.devze.com 2023-02-26 10:13 出处:网络
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 L

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 c开发者_Python百科ode 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);


I finally found that it is all because of the useage of method explain in lucene.explain only works fine with the search result,but I used it in the way with wrong input variable (query,int),and the int isn't a doc number.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号