Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart7.png 63% of files have more coverage
46   227   19   3.29
12   90   0.41   14
14     1.36  
1    
 
  SortField       Line # 33 46 19 63.9% 0.6388889
 
  (25)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.io.Serializable;
20    import java.util.Locale;
21   
22    /**
23    * Stores information about how to sort documents by terms in an individual
24    * field. Fields must be indexed in order to sort by them.
25    *
26    * <p>Created: Feb 11, 2004 1:25:29 PM
27    *
28    * @author Tim Jones (Nacimiento Software)
29    * @since lucene 1.4
30    * @version $Id: SortField.java 150357 2004-05-24 22:51:42Z tjones $
31    * @see Sort
32    */
 
33    public class SortField
34    implements Serializable {
35   
36    /** Sort by document score (relevancy). Sort values are Float and higher
37    * values are at the front. */
38    public static final int SCORE = 0;
39   
40    /** Sort by document number (index order). Sort values are Integer and lower
41    * values are at the front. */
42    public static final int DOC = 1;
43   
44    /** Guess type of sort based on field contents. A regular expression is used
45    * to look at the first term indexed for the field and determine if it
46    * represents an integer number, a floating point number, or just arbitrary
47    * string characters. */
48    public static final int AUTO = 2;
49   
50    /** Sort using term values as Strings. Sort values are String and lower
51    * values are at the front. */
52    public static final int STRING = 3;
53   
54    /** Sort using term values as encoded Integers. Sort values are Integer and
55    * lower values are at the front. */
56    public static final int INT = 4;
57   
58    /** Sort using term values as encoded Floats. Sort values are Float and
59    * lower values are at the front. */
60    public static final int FLOAT = 5;
61   
62    /** Sort using a custom Comparator. Sort values are any Comparable and
63    * sorting is done according to natural order. */
64    public static final int CUSTOM = 9;
65   
66    // IMPLEMENTATION NOTE: the FieldCache.STRING_INDEX is in the same "namespace"
67    // as the above static int values. Any new values must not have the same value
68    // as FieldCache.STRING_INDEX.
69   
70   
71    /** Represents sorting by document score (relevancy). */
72    public static final SortField FIELD_SCORE = new SortField (null, SCORE);
73   
74    /** Represents sorting by document number (index order). */
75    public static final SortField FIELD_DOC = new SortField (null, DOC);
76   
77   
78    private String field;
79    private int type = AUTO; // defaults to determining type dynamically
80    private Locale locale; // defaults to "natural order" (no Locale)
81    boolean reverse = false; // defaults to natural order
82    private SortComparatorSource factory;
83   
84    /** Creates a sort by terms in the given field where the type of term value
85    * is determined dynamically ({@link #AUTO AUTO}).
86    * @param field Name of field to sort by, cannot be <code>null</code>.
87    */
 
88  13 toggle public SortField (String field) {
89  13 this.field = field.intern();
90    }
91   
92    /** Creates a sort, possibly in reverse, by terms in the given field where
93    * the type of term value is determined dynamically ({@link #AUTO AUTO}).
94    * @param field Name of field to sort by, cannot be <code>null</code>.
95    * @param reverse True if natural order should be reversed.
96    */
 
97  5 toggle public SortField (String field, boolean reverse) {
98  5 this.field = field.intern();
99  5 this.reverse = reverse;
100    }
101   
102    /** Creates a sort by terms in the given field with the type of term
103    * values explicitly given.
104    * @param field Name of field to sort by. Can be <code>null</code> if
105    * <code>type</code> is SCORE or DOC.
106    * @param type Type of values in the terms.
107    */
 
108  56 toggle public SortField (String field, int type) {
109  56 this.field = (field != null) ? field.intern() : field;
110  56 this.type = type;
111    }
112   
113    /** Creates a sort, possibly in reverse, by terms in the given field with the
114    * type of term values explicitly given.
115    * @param field Name of field to sort by. Can be <code>null</code> if
116    * <code>type</code> is SCORE or DOC.
117    * @param type Type of values in the terms.
118    * @param reverse True if natural order should be reversed.
119    */