mirror of https://github.com/apache/lucene.git
LUCENE-5639: Fix token class to correctly implement PoistionLengthAttribute
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1592075 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1613f1882c
commit
4bd9f8b0eb
|
@ -360,14 +360,14 @@ public class Token extends CharTermAttributeImpl
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resets the term text, payload, flags, and positionIncrement,
|
/** Resets the term text, payload, flags, positionIncrement, positionLength,
|
||||||
* startOffset, endOffset and token type to default.
|
* startOffset, endOffset and token type to default.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
payload = null;
|
payload = null;
|
||||||
positionIncrement = 1;
|
positionIncrement = positionLength = 1;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
startOffset = endOffset = 0;
|
startOffset = endOffset = 0;
|
||||||
type = DEFAULT_TYPE;
|
type = DEFAULT_TYPE;
|
||||||
|
@ -391,6 +391,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
public Token clone(char[] newTermBuffer, int newTermOffset, int newTermLength, int newStartOffset, int newEndOffset) {
|
public Token clone(char[] newTermBuffer, int newTermOffset, int newTermLength, int newStartOffset, int newEndOffset) {
|
||||||
final Token t = new Token(newTermBuffer, newTermOffset, newTermLength, newStartOffset, newEndOffset);
|
final Token t = new Token(newTermBuffer, newTermOffset, newTermLength, newStartOffset, newEndOffset);
|
||||||
t.positionIncrement = positionIncrement;
|
t.positionIncrement = positionIncrement;
|
||||||
|
t.positionLength = positionLength;
|
||||||
t.flags = flags;
|
t.flags = flags;
|
||||||
t.type = type;
|
t.type = type;
|
||||||
if (payload != null)
|
if (payload != null)
|
||||||
|
@ -409,6 +410,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
endOffset == other.endOffset &&
|
endOffset == other.endOffset &&
|
||||||
flags == other.flags &&
|
flags == other.flags &&
|
||||||
positionIncrement == other.positionIncrement &&
|
positionIncrement == other.positionIncrement &&
|
||||||
|
positionLength == other.positionLength &&
|
||||||
(type == null ? other.type == null : type.equals(other.type)) &&
|
(type == null ? other.type == null : type.equals(other.type)) &&
|
||||||
(payload == null ? other.payload == null : payload.equals(other.payload)) &&
|
(payload == null ? other.payload == null : payload.equals(other.payload)) &&
|
||||||
super.equals(obj)
|
super.equals(obj)
|
||||||
|
@ -424,6 +426,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
code = code * 31 + endOffset;
|
code = code * 31 + endOffset;
|
||||||
code = code * 31 + flags;
|
code = code * 31 + flags;
|
||||||
code = code * 31 + positionIncrement;
|
code = code * 31 + positionIncrement;
|
||||||
|
code = code * 31 + positionLength;
|
||||||
if (type != null)
|
if (type != null)
|
||||||
code = code * 31 + type.hashCode();
|
code = code * 31 + type.hashCode();
|
||||||
if (payload != null)
|
if (payload != null)
|
||||||
|
@ -434,7 +437,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
// like clear() but doesn't clear termBuffer/text
|
// like clear() but doesn't clear termBuffer/text
|
||||||
private void clearNoTermBuffer() {
|
private void clearNoTermBuffer() {
|
||||||
payload = null;
|
payload = null;
|
||||||
positionIncrement = 1;
|
positionIncrement = positionLength = 1;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
startOffset = endOffset = 0;
|
startOffset = endOffset = 0;
|
||||||
type = DEFAULT_TYPE;
|
type = DEFAULT_TYPE;
|
||||||
|
@ -450,7 +453,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
clearNoTermBuffer();
|
clearNoTermBuffer();
|
||||||
copyBuffer(newTermBuffer, newTermOffset, newTermLength);
|
copyBuffer(newTermBuffer, newTermOffset, newTermLength);
|
||||||
payload = null;
|
payload = null;
|
||||||
positionIncrement = 1;
|
positionIncrement = positionLength = 1;
|
||||||
startOffset = newStartOffset;
|
startOffset = newStartOffset;
|
||||||
endOffset = newEndOffset;
|
endOffset = newEndOffset;
|
||||||
type = newType;
|
type = newType;
|
||||||
|
@ -539,6 +542,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
public void reinit(Token prototype) {
|
public void reinit(Token prototype) {
|
||||||
copyBuffer(prototype.buffer(), 0, prototype.length());
|
copyBuffer(prototype.buffer(), 0, prototype.length());
|
||||||
positionIncrement = prototype.positionIncrement;
|
positionIncrement = prototype.positionIncrement;
|
||||||
|
positionLength = prototype.positionLength;
|
||||||
flags = prototype.flags;
|
flags = prototype.flags;
|
||||||
startOffset = prototype.startOffset;
|
startOffset = prototype.startOffset;
|
||||||
endOffset = prototype.endOffset;
|
endOffset = prototype.endOffset;
|
||||||
|
@ -554,6 +558,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
public void reinit(Token prototype, String newTerm) {
|
public void reinit(Token prototype, String newTerm) {
|
||||||
setEmpty().append(newTerm);
|
setEmpty().append(newTerm);
|
||||||
positionIncrement = prototype.positionIncrement;
|
positionIncrement = prototype.positionIncrement;
|
||||||
|
positionLength = prototype.positionLength;
|
||||||
flags = prototype.flags;
|
flags = prototype.flags;
|
||||||
startOffset = prototype.startOffset;
|
startOffset = prototype.startOffset;
|
||||||
endOffset = prototype.endOffset;
|
endOffset = prototype.endOffset;
|
||||||
|
@ -571,6 +576,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
public void reinit(Token prototype, char[] newTermBuffer, int offset, int length) {
|
public void reinit(Token prototype, char[] newTermBuffer, int offset, int length) {
|
||||||
copyBuffer(newTermBuffer, offset, length);
|
copyBuffer(newTermBuffer, offset, length);
|
||||||
positionIncrement = prototype.positionIncrement;
|
positionIncrement = prototype.positionIncrement;
|
||||||
|
positionLength = prototype.positionLength;
|
||||||
flags = prototype.flags;
|
flags = prototype.flags;
|
||||||
startOffset = prototype.startOffset;
|
startOffset = prototype.startOffset;
|
||||||
endOffset = prototype.endOffset;
|
endOffset = prototype.endOffset;
|
||||||
|
@ -591,6 +597,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
super.copyTo(target);
|
super.copyTo(target);
|
||||||
((OffsetAttribute) target).setOffset(startOffset, endOffset);
|
((OffsetAttribute) target).setOffset(startOffset, endOffset);
|
||||||
((PositionIncrementAttribute) target).setPositionIncrement(positionIncrement);
|
((PositionIncrementAttribute) target).setPositionIncrement(positionIncrement);
|
||||||
|
((PositionLengthAttribute) target).setPositionLength(positionLength);
|
||||||
((PayloadAttribute) target).setPayload((payload == null) ? null : payload.clone());
|
((PayloadAttribute) target).setPayload((payload == null) ? null : payload.clone());
|
||||||
((FlagsAttribute) target).setFlags(flags);
|
((FlagsAttribute) target).setFlags(flags);
|
||||||
((TypeAttribute) target).setType(type);
|
((TypeAttribute) target).setType(type);
|
||||||
|
@ -603,6 +610,7 @@ public class Token extends CharTermAttributeImpl
|
||||||
reflector.reflect(OffsetAttribute.class, "startOffset", startOffset);
|
reflector.reflect(OffsetAttribute.class, "startOffset", startOffset);
|
||||||
reflector.reflect(OffsetAttribute.class, "endOffset", endOffset);
|
reflector.reflect(OffsetAttribute.class, "endOffset", endOffset);
|
||||||
reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", positionIncrement);
|
reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", positionIncrement);
|
||||||
|
reflector.reflect(PositionLengthAttribute.class, "positionLength", positionLength);
|
||||||
reflector.reflect(PayloadAttribute.class, "payload", payload);
|
reflector.reflect(PayloadAttribute.class, "payload", payload);
|
||||||
reflector.reflect(FlagsAttribute.class, "flags", flags);
|
reflector.reflect(FlagsAttribute.class, "flags", flags);
|
||||||
reflector.reflect(TypeAttribute.class, "type", type);
|
reflector.reflect(TypeAttribute.class, "type", type);
|
||||||
|
|
|
@ -253,6 +253,7 @@ public class TestToken extends LuceneTestCase {
|
||||||
put(OffsetAttribute.class.getName() + "#startOffset", 6);
|
put(OffsetAttribute.class.getName() + "#startOffset", 6);
|
||||||
put(OffsetAttribute.class.getName() + "#endOffset", 22);
|
put(OffsetAttribute.class.getName() + "#endOffset", 22);
|
||||||
put(PositionIncrementAttribute.class.getName() + "#positionIncrement", 1);
|
put(PositionIncrementAttribute.class.getName() + "#positionIncrement", 1);
|
||||||
|
put(PositionLengthAttribute.class.getName() + "#positionLength", 1);
|
||||||
put(PayloadAttribute.class.getName() + "#payload", null);
|
put(PayloadAttribute.class.getName() + "#payload", null);
|
||||||
put(TypeAttribute.class.getName() + "#type", TypeAttribute.DEFAULT_TYPE);
|
put(TypeAttribute.class.getName() + "#type", TypeAttribute.DEFAULT_TYPE);
|
||||||
put(FlagsAttribute.class.getName() + "#flags", 8);
|
put(FlagsAttribute.class.getName() + "#flags", 8);
|
||||||
|
|
Loading…
Reference in New Issue