Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5611: move attribute juggling to a fieldinvertstate setter

Robert Muire7b59c5a2115
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.