📄 sort.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>
Sort (Lucene 2.1.0 API)
</TITLE>
<META NAME="keywords" CONTENT="org.apache.lucene.search.Sort class">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="Sort (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/Sort.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/SimilarityDelegator.html" title="class in org.apache.lucene.search"><B>PREV CLASS</B></A>
<A HREF="../../../../org/apache/lucene/search/SortComparator.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="Sort.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 | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: <A HREF="#field_detail">FIELD</A> | <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 Sort</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.Sort</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>
<HR>
<DL>
<DT>public class <B>Sort</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>
Encapsulates sort criteria for returned hits. <p>The fields used to determine sort order must be carefully chosen. Documents must contain a single term in such a field, and the value of the term should indicate the document's relative position in a given sort order. The field must be indexed, but should not be tokenized, and does not need to be stored (unless you happen to want it back with the rest of your document data). In other words: <p><code>document.add (new Fieldable ("byNumber", Integer.toString(x), Fieldable.Store.NO, Fieldable.Index.UN_TOKENIZED));</code></p> <p><h3>Valid Types of Values</h3> <p>There are three possible kinds of term values which may be put into sorting fields: Integers, Floats, or Strings. Unless <A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search"><CODE>SortField</CODE></A> objects are specified, the type of value in the field is determined by parsing the first term in the field. <p>Integer term values should contain only digits and an optional preceeding negative sign. Values must be base 10 and in the range <code>Integer.MIN_VALUE</code> and <code>Integer.MAX_VALUE</code> inclusive. Documents which should appear first in the sort should have low value integers, later documents high values (i.e. the documents should be numbered <code>1..n</code> where <code>1</code> is the first and <code>n</code> the last). <p>Float term values should conform to values accepted by <A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/Float.html" title="class or interface in java.lang"><CODE>Float.valueOf(String)</CODE></A> (except that <code>NaN</code> and <code>Infinity</code> are not supported). Documents which should appear first in the sort should have low values, later documents high values. <p>String term values can contain any valid String, but should not be tokenized. The values are sorted according to their <A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/Comparable.html" title="class or interface in java.lang"><CODE>natural order</CODE></A>. Note that using this type of term value has higher memory requirements than the other two types. <p><h3>Object Reuse</h3> <p>One of these objects can be used multiple times and the sort order changed between usages. <p>This class is thread safe. <p><h3>Memory Usage</h3> <p>Sorting uses of caches of term values maintained by the internal HitQueue(s). The cache is static and contains an integer or float array of length <code>IndexReader.maxDoc()</code> for each field name for which a sort is performed. In other words, the size of the cache in bytes is: <p><code>4 * IndexReader.maxDoc() * (# of different fields actually used to sort)</code> <p>For String fields, the cache is larger: in addition to the above array, the value of every term in the field is kept in memory. If there are many unique terms in the field, this could be quite large. <p>Note that the size of the cache is not affected by how many fields are in the index and <i>might</i> be used to sort - only by the ones actually used to sort a result set. <p>Created: Feb 12, 2004 10:53:57 AM
<P>
<P>
<DL>
<DT><B>Since:</B></DT> <DD>lucene 1.4</DD><DT><B>Version:</B></DT> <DD>$Id: Sort.java 472959 2006-11-09 16:21:50Z yonik $</DD><DT><B>Author:</B></DT> <DD>Tim Jones (Nacimiento Software)</DD><DT><B>See Also:</B><DD><A HREF="../../../../serialized-form.html#org.apache.lucene.search.Sort">Serialized Form</A></DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<A NAME="field_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Field Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static <A HREF="../../../../org/apache/lucene/search/Sort.html" title="class in org.apache.lucene.search">Sort</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#INDEXORDER">INDEXORDER</A></B></CODE>
<BR>
Represents sorting by index order.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static <A HREF="../../../../org/apache/lucene/search/Sort.html" title="class in org.apache.lucene.search">Sort</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#RELEVANCE">RELEVANCE</A></B></CODE>
<BR>
Represents sorting by computed relevance.</TD>
</TR>
</TABLE>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort()">Sort</A></B>()</CODE>
<BR>
Sorts by computed relevance.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort(org.apache.lucene.search.SortField)">Sort</A></B>(<A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search">SortField</A> field)</CODE>
<BR>
Sorts by the criteria in the given SortField.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort(org.apache.lucene.search.SortField[])">Sort</A></B>(<A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search">SortField</A>[] fields)</CODE>
<BR>
Sorts in succession by the criteria in each SortField.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort(java.lang.String)">Sort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A> field)</CODE>
<BR>
Sorts by the terms in <code>field</code> then by index order (document number).</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort(java.lang.String[])">Sort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A>[] fields)</CODE>
<BR>
Sorts in succession by the terms in each field.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#Sort(java.lang.String, boolean)">Sort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A> field, boolean reverse)</CODE>
<BR>
Sorts possibly in reverse by the terms in <code>field</code> then by index order (document number).</TD>
</TR>
</TABLE>
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search">SortField</A>[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#getSort()">getSort</A></B>()</CODE>
<BR>
Representation of the sort criteria.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#setSort(org.apache.lucene.search.SortField)">setSort</A></B>(<A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search">SortField</A> field)</CODE>
<BR>
Sets the sort to the given criteria.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#setSort(org.apache.lucene.search.SortField[])">setSort</A></B>(<A HREF="../../../../org/apache/lucene/search/SortField.html" title="class in org.apache.lucene.search">SortField</A>[] fields)</CODE>
<BR>
Sets the sort to the given criteria in succession.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#setSort(java.lang.String)">setSort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A> field)</CODE>
<BR>
Sets the sort to the terms in <code>field</code> then by index order (document number).</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#setSort(java.lang.String[])">setSort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A>[] fieldnames)</CODE>
<BR>
Sets the sort to the terms in each field in succession.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/lucene/search/Sort.html#setSort(java.lang.String, boolean)">setSort</A></B>(<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html" title="class or interface in java.lang">String</A> field, boolean reverse)</CODE>
<BR>
Sets the sort to the terms in <code>field</code> possibly in reverse, then by index order (document number).</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -