| Index: FieldSortedHitQueue.java
|
| ===================================================================
|
| --- FieldSortedHitQueue.java (revision 654583)
|
| +++ FieldSortedHitQueue.java (working copy)
|
| @@ -53,7 +53,12 @@
|
| this.fields = new SortField[n]; |
| for (int i=0; i<n; ++i) { |
| String fieldname = fields[i].getField(); |
| - comparators[i] = getCachedComparator (reader, fieldname, fields[i].getType(), fields[i].getLocale(), fields[i].getFactory()); |
| + |
| + if(fields[i].getFactory() instanceof SortComparatorSourceUncacheable) { // no caching to avoid memory leak |
| + comparators[i] = getComparator (reader, fieldname, fields[i].getType(), fields[i].getLocale(), fields[i].getFactory()); |
| + } else { |
| + comparators[i] = getCachedComparator (reader, fieldname, fields[i].getType(), fields[i].getLocale(), fields[i].getFactory()); |
| + } |
| |
| if (comparators[i].sortType() == SortField.STRING) { |
| this.fields[i] = new SortField (fieldname, fields[i].getLocale(), fields[i].getReverse()); |
| @@ -157,7 +162,18 @@
|
| SortField[] getFields() { |
| return fields; |
| } |
| - |
| + |
| + static ScoreDocComparator getComparator (IndexReader reader, String field, int type, Locale locale, SortComparatorSource factory) |
| + throws IOException { |
| + if (type == SortField.DOC) return ScoreDocComparator.INDEXORDER; |
| + if (type == SortField.SCORE) return ScoreDocComparator.RELEVANCE; |
| + FieldCacheImpl.Entry entry = (factory != null) |
| + ? new FieldCacheImpl.Entry (field, factory) |
| + : new FieldCacheImpl.Entry (field, type, locale); |
| + return (ScoreDocComparator)Comparators.createValue(reader, entry); |
| + } |
| + |
| + |
| static ScoreDocComparator getCachedComparator (IndexReader reader, String field, int type, Locale locale, SortComparatorSource factory) |
| throws IOException { |
| if (type == SortField.DOC) return ScoreDocComparator.INDEXORDER; |
| Index: SortComparatorSourceUncacheable.java
|
| ===================================================================
|
| --- SortComparatorSourceUncacheable.java (revision 0)
|
| +++ SortComparatorSourceUncacheable.java (revision 0)
|
| @@ -0,0 +1,16 @@
|
| +package org.apache.lucene.search;
|
| +
|
| +import org.apache.lucene.index.IndexReader;
|
| +import java.io.IOException;
|
| +import java.io.Serializable;
|
| +
|
| +/**
|
| + * Expert: returns a comparator for sorting ScoreDocs.
|
| + *
|
| + * <p>Created: May 23, 2008 3:49:28 PM
|
| + *
|
| + * @version $Id: SortComparatorSourceUncacheable.java 564236 2008-05-23 15:21:19Z EthanT $
|
| + * @since 1.6
|
| + */
|
| +public interface SortComparatorSourceUncacheable extends Serializable {
|
| +}
|