江恩买卖十二法则word:Lucene排序算法

来源:百度文库 编辑:中财网 时间:2024/04/28 08:44:41

The score of query q for document d correlates to thecosine-distance or dot-product between document and query vectors in aVector Space Model (VSM) of Information Retrieval.A document whose vector is closer to the query vector in that model is scored higher.The score is computed as follows:

score(q,d)   =   coord(q,d)  ·  queryNorm(q)  ·  ( tf(t in d)  ·  idf(t)2  ·  t.getBoost() ·  norm(t,d) )
t in q

where

  1. tf(t in d) correlates to the term's frequency, defined as the number of times term t appears in the currently scored document d. Documents that have more occurrences of a given term receive a higher score. The default computation for tf(t in d) in DefaultSimilarity is:
     
    tf(t in d)   =   frequency½
     
  2. idf(t) stands for Inverse Document Frequency. This value correlates to the inverse of docFreq (the number of documents in which the term t appears). This means rarer terms give higher contribution to the total score. The default computation for idf(t) in DefaultSimilarity is:
     
    idf(t)  =   1 + log ( numDocs ––––––––– docFreq+1 )
     
  3. coord(q,d) is a score factor based on how many of the query terms are found in the specified document. Typically, a document that contains more of the query's terms will receive a higher score than another document with fewer query terms. This is a search time factor computed in coord(q,d) by the Similarity in effect at search time.
     
  4. queryNorm(q) is a normalizing factor used to make scores between queries comparable. This factor does not affect document ranking (since all ranked documents are multiplied by the same factor), but rather just attempts to make scores from different queries (or even different indexes) comparable. This is a search time factor computed by the Similarity in effect at search time. The default computation in DefaultSimilarity is:
     
    queryNorm(q)   =   queryNorm(sumOfSquaredWeights)   =   1 –––––––––––––– sumOfSquaredWeights½
     
    The sum of squared weights (of the query terms) is computed by the query Weight object. For example, a boolean query computes this value as:
     
    sumOfSquaredWeights   =   q.getBoost() 2  ·  ( idf(t)  ·  t.getBoost() ) 2
    t in q

     
  5. t.getBoost() is a search time boost of term t in the query q as specified in the query text (see query syntax), or as set by application calls to setBoost(). Notice that there is really no direct API for accessing a boost of one term in a multi term query, but rather multi terms are represented in a query as multi TermQuery objects, and so the boost of a term in the query is accessible by calling the sub-query getBoost().
     
  6. norm(t,d) encapsulates a few (indexing time) boost and length factors:
    • 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) - computed when the document is added to the index in accordance with the number of tokens of this field in the document, so that shorter fields contribute more to the score. LengthNorm is computed by the Similarity class in effect at indexing.

    When a document is added to the index, all the above factors are multiplied. If the document has multiple fields with the same name, all their boosts are multiplied together:
     

    norm(t,d)   =   doc.getBoost()  ·  lengthNorm(field)  ·  f.getBoost()
    field f in d named as t

     
    However the resulted norm value is encoded as a single byte before being stored. At search time, the norm byte value is read from the index directory and decoded back to a float norm value. This encoding/decoding, while reducing index size, comes with the price of precision loss - 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.