lucene2 4原始碼學習9 搜尋 norm

2021-09-01 17:23:57 字數 1307 閱讀 8001

public float score()

計算得分的時候要用到norm。這個norm是怎麼來的呢

public scorer scorer(indexreader reader) throws ioexception

看到score是從reader中來的。

norm是在segmentreader的opennorms設定的。

private void opennorms(directory cfsdir, int readbuffersize) throws ioexception 

if (fi.isindexed && !fi.omitnorms)

// singlenormfile means multiple norms share this file

boolean singlenormfile = filename.endswith("." + indexfilenames.norms_extension);

indexinput norminput = null;

long normseek;

if (singlenormfile)

// all norms in the .nrm file can share a single indexinput since

// they are only used in a synchronized context.

// if this were to change in the future, a clone could be done here.

norminput = singlenormstream;

} else

norms.put(fi.name, new norm(norminput, singlenormfile, fi.number, normseek));

nextnormseek += maxdoc; // increment also if some norms are separate}}

}

indexreader:

public void setnorm(int doc, string field, float value)

throws stalereaderexception, corruptindexexception, lockobtainfailedexception, ioexception

是在這裡設定norm的,但是沒看到有呼叫這個方法的地方。

lucene2 4原始碼學習1

先來看看lucene的總體情況 img 可以看到lucene 行數是36099行,一共344個類。當然注釋也有18302行。是 行數的一半,這個其實是很好的,但是對於英文不好的我表示比較蛋疼。而且indexwrite有2000多行 有點多,還好這樣的模擬較少,絕大多數都是200行以下。這點也是給了不...

lucene搜尋原始碼過程簡析

今天來談下有關在lucene中,如何完成乙個搜尋的過程,用過lucene的朋友都會經常用到如下的一段 query query parser.parse searchtext 解析構建query樹 topdocs td search.search query,100 檢索的入口,限制返回結果集100 ...

9 學習Lucene3 5索引搜尋之其他搜尋

1 lucene3.5索引搜尋之字首搜尋 lucene搜尋之prefixquery 字首搜尋 public void searchbyprefixquery string field,string value 2 lucene3.5索引搜尋之萬用字元搜尋 lucene搜尋之prefixquery 萬...