From e7b59c5a2115678ccf258d36f22d909144398834 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 28 Apr 2014 18:55:37 +0000 Subject: [PATCH] LUCENE-5611: move attribute juggling to a fieldinvertstate setter git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5611@1590747 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/DefaultIndexingChain.java | 10 +--------- .../org/apache/lucene/index/FieldInvertState.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java index 6d65a9789fb..c1e01c17e40 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java +++ b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java @@ -544,15 +544,7 @@ final class DefaultIndexingChain extends DocConsumer { try (TokenStream stream = field.tokenStream(docState.analyzer)) { // reset the TokenStream to the first token stream.reset(); - - if (invertState.attributeSource != stream) { - // EmptyTokenStream gets angry otherwise: - invertState.termAttribute = stream.getAttribute(TermToBytesRefAttribute.class); - invertState.posIncrAttribute = stream.addAttribute(PositionIncrementAttribute.class); - invertState.offsetAttribute = stream.addAttribute(OffsetAttribute.class); - invertState.payloadAttribute = stream.getAttribute(PayloadAttribute.class); - invertState.attributeSource = stream; - } + invertState.setAttributeSource(stream); termsHashPerField.start(field, first); diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java b/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java index be7b346a40d..80f0bbe8d31 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java +++ b/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java @@ -75,6 +75,20 @@ public final class FieldInvertState { uniqueTermCount = 0; boost = 1.0f; } + + // TODO: better name? + /** + * Sets attributeSource to a new instance. + */ + void setAttributeSource(AttributeSource attributeSource) { + if (this.attributeSource != attributeSource) { + this.attributeSource = attributeSource; + termAttribute = attributeSource.getAttribute(TermToBytesRefAttribute.class); + posIncrAttribute = attributeSource.addAttribute(PositionIncrementAttribute.class); + offsetAttribute = attributeSource.addAttribute(OffsetAttribute.class); + payloadAttribute = attributeSource.getAttribute(PayloadAttribute.class); + } + } /** * Get the last processed term position.