1 package org.apache.lucene.search; 2 3 18 19 import java.io.Serializable ; 20 import java.util.Locale ; 21 22 33 public class SortField 34 implements Serializable { 35 36 38 public static final int SCORE = 0; 39 40 42 public static final int DOC = 1; 43 44 48 public static final int AUTO = 2; 49 50 52 public static final int STRING = 3; 53 54 56 public static final int INT = 4; 57 58 60 public static final int FLOAT = 5; 61 62 64 public static final int CUSTOM = 9; 65 66 70 71 72 public static final SortField FIELD_SCORE = new SortField (null, SCORE); 73 74 75 public static final SortField FIELD_DOC = new SortField (null, DOC); 76 77 78 private String field; 79 private int type = AUTO; private Locale locale; boolean reverse = false; private SortComparatorSource factory; 83 84 88 public SortField (String field) { 89 this.field = field.intern(); 90 } 91 92 97 public SortField (String field, boolean reverse) { 98 this.field = field.intern(); 99 this.reverse = reverse; 100 } 101 102 108 public SortField (String field, int type) { 109 this.field = (field != null) ? field.intern() : field; 110 this.type = type; 111 } 112 113 120 public SortField (String field, int type, boolean reverse) { 121 this.field = (field != null) ? field.intern() : field; 122 this.type = type; 123 this.reverse = reverse; 124 } 125 126 131 public SortField (String field, Locale locale) { 132 this.field = field.intern(); 133 this.type = STRING; 134 this.locale = locale; 135 } 136 137 142 public SortField (String field, Locale locale, boolean reverse) { 143 this.field = field.intern(); 144 this.type = STRING; 145 this.locale = locale; 146 this.reverse = reverse; 147 } 148 149 153 public SortField (String field, SortComparatorSource comparator) { 154 this.field = (field != null) ? field.intern() : field; 155 this.type = CUSTOM; 156 this.factory = comparator; 157 } 158 159 164 public SortField (String field, SortComparatorSource comparator, boolean reverse) { 165 this.field = (field != null) ? field.intern() : field; 166 this.type = CUSTOM; 167 this.reverse = reverse; 168 this.factory = comparator; 169 } 170 171 175 public String getField() { 176 return field; 177 } 178 179 182 public int getType() { 183 return type; 184 } 185 186 190 public Locale getLocale() { 191 return locale; 192 } 193 194 197 public boolean getReverse() { 198 return reverse; 199 } 200 201 public SortComparatorSource getFactory() { 202 return factory; 203 } 204 205 public String toString() { 206 StringBuffer buffer = new StringBuffer (); 207 switch (type) { 208 case SCORE: buffer.append("<score>"); 209 break; 210 211 case DOC: buffer.append("<doc>"); 212 break; 213 214 case CUSTOM: buffer.append ("<custom:\"" + field + "\": " 215 + factory + ">"); 216 break; 217 218 default: buffer.append("\"" + field + "\""); 219 break; 220 } 221 222 if (locale != null) buffer.append ("("+locale+")"); 223 if (reverse) buffer.append('!'); 224 225 return buffer.toString(); 226 } 227 } 228 | Popular Tags |