1 package org.apache.lucene.search; 2 3 18 19 import java.io.Serializable ; 20 21 22 100 public class Sort 101 implements Serializable { 102 103 109 public static final Sort RELEVANCE = new Sort(); 110 111 112 public static final Sort INDEXORDER = new Sort(SortField.FIELD_DOC); 113 114 SortField[] fields; 116 117 122 public Sort() { 123 this(new SortField[] { SortField.FIELD_SCORE, SortField.FIELD_DOC }); 124 } 125 126 133 public Sort(String field) { 134 setSort(field, false); 135 } 136 137 144 public Sort(String field, boolean reverse) { 145 setSort(field, reverse); 146 } 147 148 154 public Sort(String [] fields) { 155 setSort(fields); 156 } 157 158 159 public Sort(SortField field) { 160 setSort(field); 161 } 162 163 164 public Sort(SortField[] fields) { 165 setSort(fields); 166 } 167 168 172 public final void setSort(String field) { 173 setSort(field, false); 174 } 175 176 180 public void setSort(String field, boolean reverse) { 181 SortField[] nfields = new SortField[] { 182 new SortField(field, SortField.AUTO, reverse), SortField.FIELD_DOC }; 183 fields = nfields; 184 } 185 186 187 public void setSort(String [] fieldnames) { 188 final int n = fieldnames.length; 189 SortField[] nfields = new SortField[n]; 190 for (int i = 0; i < n; ++i) { 191 nfields[i] = new SortField(fieldnames[i], SortField.AUTO); 192 } 193 fields = nfields; 194 } 195 196 197 public void setSort(SortField field) { 198 this.fields = new SortField[] { field }; 199 } 200 201 202 public void setSort(SortField[] fields) { 203 this.fields = fields; 204 } 205 206 210 public SortField[] getSort() { 211 return fields; 212 } 213 214 public String toString() { 215 StringBuffer buffer = new StringBuffer (); 216 217 for (int i = 0; i < fields.length; i++) { 218 buffer.append(fields[i].toString()); 219 if ((i+1) < fields.length) 220 buffer.append(','); 221 } 222 223 return buffer.toString(); 224 } 225 } 226 | Popular Tags |