Skip to content

Apache Lucene open-source search software

LUCENE-1582: enable FieldCache.Parser to stop early

Michael McCandlessb86ded6faecc
diff --git a/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java b/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java
index 626ee281864..abe4c4cac1e 100644
--- a/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java
+++ b/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java
@@ -73,6 +73,7 @@ class ExtendedFieldCacheImpl extends FieldCacheImpl implements ExtendedFieldCach
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();
@@ -113,6 +114,7 @@ class ExtendedFieldCacheImpl extends FieldCacheImpl implements ExtendedFieldCach
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();
diff --git a/src/java/org/apache/lucene/search/FieldCache.java b/src/java/org/apache/lucene/search/FieldCache.java
index 09815b57254..a852c596e17 100644
--- a/src/java/org/apache/lucene/search/FieldCache.java
+++ b/src/java/org/apache/lucene/search/FieldCache.java
@@ -82,6 +82,18 @@ public interface FieldCache {
public interface Parser {
}
+ /**
+ * Expert: when thrown from a custom Parser, this stops
+ * processing terms and returns the current FieldCache
+ * array.
+ *
+ * <p><b>NOTE</b>: This API is experimental and likely to
+ * change in incompatible ways, or be removed entirely, in
+ * the next release.
+ */
+ public static class StopFillCacheException extends RuntimeException {
+ }
+
/** Interface to parse bytes from document fields.
* @see FieldCache#getBytes(IndexReader, String, FieldCache.ByteParser)
*/
diff --git a/src/java/org/apache/lucene/search/FieldCacheImpl.java b/src/java/org/apache/lucene/search/FieldCacheImpl.java
index 7f062c3ad79..33ee6bdb5f0 100644
--- a/src/java/org/apache/lucene/search/FieldCacheImpl.java
+++ b/src/java/org/apache/lucene/search/FieldCacheImpl.java
@@ -196,6 +196,7 @@ implements FieldCache {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();
@@ -235,6 +236,7 @@ implements FieldCache {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();
@@ -274,6 +276,7 @@ implements FieldCache {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();
@@ -315,6 +318,7 @@ implements FieldCache {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
+ } catch (StopFillCacheException stop) {
} finally {
termDocs.close();
termEnum.close();