Index: src/java/org/apache/lucene/search/FieldCacheImpl.java =================================================================== --- src/java/org/apache/lucene/search/FieldCacheImpl.java (revision 723374) +++ src/java/org/apache/lucene/search/FieldCacheImpl.java (working copy) @@ -88,7 +88,7 @@ static class Entry { final String field; // which Fieldable final int type; // which SortField type - final Object custom; // which custom comparator + final Object custom; // which custom comparator or parser final Locale locale; // the locale we're sorting (if string) /** Creates one of these objects. */ @@ -99,7 +99,7 @@ this.locale = locale; } - /** Creates one of these objects for a custom comparator. */ + /** Creates one of these objects for a custom comparator/parser. */ Entry (String field, Object custom) { this.field = field.intern(); this.type = SortField.CUSTOM; @@ -107,6 +107,14 @@ this.locale = null; } + /** Creates one of these objects for a custom type with parser, needed by FieldSortedHitQueue. */ + Entry (String field, Object parser, int type) { + this.field = field.intern(); + this.type = type; + this.custom = parser; + this.locale = null; + } + /** Two of these are equal iff they reference the same field and type. */ public boolean equals (Object o) { if (o instanceof Entry) { Index: src/java/org/apache/lucene/search/FieldSortedHitQueue.java =================================================================== --- src/java/org/apache/lucene/search/FieldSortedHitQueue.java (revision 723374) +++ src/java/org/apache/lucene/search/FieldSortedHitQueue.java (working copy) @@ -52,12 +52,12 @@ this.fields = new SortField[n]; for (int i=0; inull if + * type is SCORE or DOC. + * @param type Type of values in the terms. + * @param parser Instance of a {@link FieldCache} parser that fits to the given type. + */ + public SortField (String field, int type, Object parser) { + this.field = (field != null) ? field.intern() : field; + this.type = type; + this.parser = parser; + } + + /** Creates a sort, possibly in reverse, by terms in the given field with the + * type of term values explicitly given. + * @param field Name of field to sort by. Can be null if + * type is SCORE or DOC. + * @param type Type of values in the terms. + * @param parser Instance of a {@link FieldCache} parser that fits to the given type. + * @param reverse True if natural order should be reversed. + */ + public SortField (String field, int type, Object parser, boolean reverse) { + this.field = (field != null) ? field.intern() : field; + this.type = type; + this.reverse = reverse; + this.parser = parser; + } + /** Creates a sort by terms in the given field sorted * according to the given locale. * @param field Name of field to sort by, cannot be null. @@ -210,6 +239,14 @@ return locale; } + /** Returns the instance of a {@link FieldCache} parser that fits to the given sort type. + * May return null if no parser was specified. Sorting is using the default parser then. + * @return An instance of a {@link FieldCache} parser, or null. + */ + public Object getParser() { + return parser; + } + /** Returns whether the sort should be reversed. * @return True if natural order should be reversed. */ @@ -240,6 +277,7 @@ } if (locale != null) buffer.append('(').append(locale).append(')'); + if (parser != null) buffer.append('(').append(parser).append(')'); if (reverse) buffer.append('!'); return buffer.toString();