📄 similarity.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.4.2_04) on Wed Feb 14 11:49:18 EST 2007 -->
<TITLE>
Similarity (Lucene 2.1.0 API)
</TITLE>
<META NAME="keywords" CONTENT="org.apache.lucene.search.Similarity class">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="Similarity (Lucene 2.1.0 API)";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Similarity.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../org/apache/lucene/search/Searcher.html" title="class in org.apache.lucene.search"><B>PREV CLASS</B></A>
<A HREF="../../../../org/apache/lucene/search/SimilarityDelegator.html" title="class in org.apache.lucene.search"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html" target="_top"><B>FRAMES</B></A>
<A HREF="Similarity.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
org.apache.lucene.search</FONT>
<BR>
Class Similarity</H2>
<PRE>
<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html" title="class or interface in java.lang">java.lang.Object</A>
<IMG SRC="../../../../resources/inherit.gif" ALT="extended by"><B>org.apache.lucene.search.Similarity</B>
</PRE>
<DL>
<DT><B>All Implemented Interfaces:</B> <DD><A HREF="http://java.sun.com/j2se/1.4/docs/api/java/io/Serializable.html" title="class or interface in java.io">Serializable</A></DD>
</DL>
<DL>
<DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html" title="class in org.apache.lucene.search">DefaultSimilarity</A>, <A HREF="../../../../org/apache/lucene/search/SimilarityDelegator.html" title="class in org.apache.lucene.search">SimilarityDelegator</A></DD>
</DL>
<HR>
<DL>
<DT>public abstract class <B>Similarity</B><DT>extends <A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html" title="class or interface in java.lang">Object</A><DT>implements <A HREF="http://java.sun.com/j2se/1.4/docs/api/java/io/Serializable.html" title="class or interface in java.io">Serializable</A></DL>
<P>
Expert: Scoring API. <p>Subclasses implement search scoring. <p>The score of query <code>q</code> for document <code>d</code> correlates to the cosine-distance or dot-product between document and query vectors in a <a href="http://en.wikipedia.org/wiki/Vector_Space_Model"> Vector Space Model (VSM) of Information Retrieval</a>. A document whose vector is closer to the query vector in that model is scored higher. The score is computed as follows: <P> <table cellpadding="1" cellspacing="0" border="1" align="center"> <tr><td> <table cellpadding="1" cellspacing="0" border="0" align="center"> <tr> <td valign="middle" align="right" rowspan="1"> score(q,d) = <A HREF="#formula_coord">coord(q,d)</A> · <A HREF="#formula_queryNorm">queryNorm(q)</A> · </td> <td valign="bottom" align="center" rowspan="1"> <big><big><big>∑</big></big></big> </td> <td valign="middle" align="right" rowspan="1"> <big><big>(</big></big> <A HREF="#formula_tf">tf(t in d)</A> · <A HREF="#formula_idf">idf(t)</A><sup>2</sup> · <A HREF="#formula_termBoost">t.getBoost()</A> · <A HREF="#formula_norm">norm(t,d)</A> <big><big>)</big></big> </td> </tr> <tr valigh="top"> <td></td> <td align="center"><small>t in q</small></td> <td></td> </tr> </table> </td></tr> </table> <p> where <ol> <li> <A NAME="formula_tf"></A> <b>tf(t in d)</b> correlates to the term's <i>frequency</i>, defined as the number of times term <i>t</i> appears in the currently scored document <i>d</i>. Documents that have more occurrences of a given term receive a higher score. The default computation for <i>tf(t in d)</i> in <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#tf(float)"><CODE>DefaultSimilarity</CODE></A> is: <br> <br> <table cellpadding="2" cellspacing="2" border="0" align="center"> <tr> <td valign="middle" align="right" rowspan="1"> <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#tf(float)"><CODE>tf(t in d)</CODE></A> = </td> <td valign="top" align="center" rowspan="1"> frequency<sup><big>½</big></sup> </td> </tr> </table> <br> <br> </li> <li> <A NAME="formula_idf"></A> <b>idf(t)</b> stands for Inverse Document Frequency. This value correlates to the inverse of <i>docFreq</i> (the number of documents in which the term <i>t</i> appears). This means rarer terms give higher contribution to the total score. The default computation for <i>idf(t)</i> in <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#idf(int, int)"><CODE>DefaultSimilarity</CODE></A> is: <br> <br> <table cellpadding="2" cellspacing="2" border="0" align="center"> <tr> <td valign="middle" align="right"> <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#idf(int, int)"><CODE>idf(t)</CODE></A> = </td> <td valign="middle" align="center"> 1 + log <big>(</big> </td> <td valign="middle" align="center"> <table> <tr><td align="center"><small>numDocs</small></td></tr> <tr><td align="center">–––––––––</td></tr> <tr><td align="center"><small>docFreq+1</small></td></tr> </table> </td> <td valign="middle" align="center"> <big>)</big> </td> </tr> </table> <br> <br> </li> <li> <A NAME="formula_coord"></A> <b>coord(q,d)</b> 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 <A HREF="../../../../org/apache/lucene/search/Similarity.html#coord(int, int)"><CODE>coord(q,d)</CODE></A> by the Similarity in effect at search time. <br> <br> </li> <li><b> <A NAME="formula_queryNorm"></A> queryNorm(q) </b> 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 <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#queryNorm(float)"><CODE>DefaultSimilarity</CODE></A> is: <br> <br> <table cellpadding="1" cellspacing="0" border="0" align="center"> <tr> <td valign="middle" align="right" rowspan="1"> queryNorm(q) = <A HREF="../../../../org/apache/lucene/search/DefaultSimilarity.html#queryNorm(float)"><CODE>queryNorm(sumOfSquaredWeights)</CODE></A> = </td> <td valign="middle" align="center" rowspan="1"> <table> <tr><td align="center"><big>1</big></td></tr> <tr><td align="center"><big> –––––––––––––– </big></td></tr> <tr><td align="center">sumOfSquaredWeights<sup><big>½</big></sup></td></tr> </table> </td> </tr> </table> <br> <br> The sum of squared weights (of the query terms) is computed by the query <A HREF="../../../../org/apache/lucene/search/Weight.html" title="interface in org.apache.lucene.search"><CODE>Weight</CODE></A> object. For example, a <A HREF="../../../../org/apache/lucene/search/BooleanQuery.html" title="class in org.apache.lucene.search"><CODE>boolean query</CODE></A> computes this value as: <br> <br> <table cellpadding="1" cellspacing="0" border="0"n align="center"> <tr> <td valign="middle" align="right" rowspan="1"> <A HREF="../../../../org/apache/lucene/search/Weight.html#sumOfSquaredWeights()"><CODE>sumOfSquaredWeights</CODE></A> = <A HREF="../../../../org/apache/lucene/search/Query.html#getBoost()"><CODE>q.getBoost()</CODE></A> <sup><big>2</big></sup> · </td> <td valign="bottom" align="center" rowspan="1"> <big><big><big>∑</big></big></big> </td> <td valign="middle" align="right" rowspan="1"> <big><big>(</big></big> <A HREF="#formula_idf">idf(t)</A> · <A HREF="#formula_termBoost">t.getBoost()</A> <big><big>) <sup>2</sup> </big></big> </td> </tr> <tr valigh="top"> <td></td> <td align="center"><small>t in q</small></td> <td></td> </tr> </table> <br> <br> </li> <li> <A NAME="formula_termBoost"></A> <b>t.getBoost()</b> is a search time boost of term <i>t</i> in the query <i>q</i> as specified in the query text (see <A HREF="../../../../../queryparsersyntax.html#Boosting a Term">query syntax</A>), or as set by application calls to <A HREF="../../../../org/apache/lucene/search/Query.html#setBoost(float)"><CODE>setBoost()</CODE></A>. 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 <A HREF="../../../../org/apache/lucene/search/TermQuery.html" title="class in org.apache.lucene.search"><CODE>TermQuery</CODE></A> objects, and so the boost of a term in the query is accessible by calling the sub-query <A HREF="../../../../org/apache/lucene/search/Query.html#getBoost()"><CODE>getBoost()</CODE></A>. <br> <br> </li> <li> <A NAME="formula_norm"></A> <b>norm(t,d)</b> encapsulates a few (indexing time) boost and length factors: <ul> <li><b>Document boost</b> - set by calling <A HREF="../../../../org/apache/lucene/document/Document.html#setBoost(float)"><CODE>doc.setBoost()</CODE></A> before adding the document to the index. </li> <li><b>Field boost</b> - set by calling <A HREF="../../../../org/apache/lucene/document/Fieldable.html#setBoost(float)"><CODE>field.setBoost()</CODE></A> before adding the field to a document. </li> <li><A HREF="../../../../org/apache/lucene/search/Similarity.html#lengthNorm(java.lang.String, int)"><CODE><b>lengthNorm</b>(field)</CODE></A> - 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. </li> </ul> <p> 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:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -