說明見Similarity.java的javadoc信息:
算法請參考javadoc的,它使用的是Vector Space Model (VSM) of Information Retrieval。
針對一條查詢語句q(query),一個d(document)的得分公式
其中,
tf(t in d) 表示某個term的出現頻率,定義了term t出現在當前地document d的次數。 那些query中給定地term,如果出現越多次的,得分越高
。它在默認實現DefaultSimilarity的公式為
idf(t) 表示反向文檔頻率。這個參數表示docFreq(term t一共在多少個文檔中出現)的反向影響值。它意味著在越少文檔中出現的terms貢獻越高地分數。它在默認實現DefaultSimilarity的公式為:
idf(t) = |
1 + log ( |
numDocs |
––––––––– |
docFreq+1 |
|
) |
coord(q,d) 是一個基于在該文檔中出現了多少個query中的terms的得分
因素。文檔中出現的query中的terms數量/query總共多少個query數量。典型的,一個文檔包含越多地query中的terms會得到更高地分。This is a search time factor computed in coord(q,d)
by the Similarity in effect at search time.
queryNorm(q) 是一個標準化參數,它是用來區分比較不同queries時的因素,這個因素不影響document ranking (因為所有的ranked document都會乘以相同的值),但是不同地queries(或這不同地indexes中)它會得到不同的可用于比較的值。This is a search time factor computed by the Similarity in effect at search time. 它在默認實現DefaultSimilarity的公式為:
其中的sumOfSquaredWeights(of the query terms)是根據the query
Weight
object計算出來的. For example, a
boolean query
computes this value as:
t.getBoost() 是一個term t在query q中的search time boost, 它是在the query text (see
query syntax)中指定的, 或者被應用程序直接調用
setBoost()
設置的. 注意,這兒沒有直接的API去訪問在 a multi term query的一個term的boost值,但是multi terms會以multi
TermQuery
objects在一個query中被表示,因此the boost of a term in the query可以使用子query的
getBoost()
反問到.
norm(t,d) 封裝(encapsulates)了一些(indexing time)的boost和length factors: ???這個參數之和field中tokens的數量有關,和term本身無關???
Document boost - set by calling
doc.setBoost()
before adding the document to the index.
Field boost - set by calling
field.setBoost()
before adding the field to a document.
lengthNorm(field)
-。當文檔被加入到索引時計算,,和document的field
中的tokens的數量有關,因此,一個比較短的fields貢獻更高的分數。LengthNorm is computed by the Similarity class in effect at indexing. DefaultSimilarity中的實現為(float)(1.0 / Math.sqrt(numTerms));
當一個文檔被加入索引時,上述因素會被相乘。如果文檔有多個fields同名,他們的boosts數值會被多次相乘。
但是
,計算出的norm數值在存儲時是使用一個a single byte編碼的。search時,這個norm byte從index directory讀取,并且被解碼回float。這個編碼/解碼算法會產生精度丟失。 - it is not guaranteed that decode(encode(x)) = x. For instance, decode(encode(0.89)) = 0.75. Also notice that search time is too late to modify this norm part of scoring, e.g. by using a different Similarity
for search.