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
This commit is contained in:
Robert Muir 2014-04-28 18:55:37 +00:00
parent f0414ff3af
commit e7b59c5a21
2 changed files with 15 additions and 9 deletions

View File

@ -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);

View File

@ -76,6 +76,20 @@ public final class FieldInvertState {
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.
* @return the position