From d72134b46eba627cc45b5646620172d9bd686e9b Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 4 Jul 2016 15:58:27 +0200 Subject: [PATCH] Fix CompletionSuggestSearchIT and CompletionSuggestSearch2xIT --- .../completion2x/CompletionTokenStream.java | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion2x/CompletionTokenStream.java b/core/src/main/java/org/elasticsearch/search/suggest/completion2x/CompletionTokenStream.java index 2c752d64175..bdfcb9eff11 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion2x/CompletionTokenStream.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion2x/CompletionTokenStream.java @@ -23,8 +23,11 @@ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; +import org.apache.lucene.util.AttributeImpl; +import org.apache.lucene.util.AttributeReflector; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; +import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.IntsRef; import org.apache.lucene.util.fst.Util; @@ -105,8 +108,8 @@ public final class CompletionTokenStream extends TokenStream { input.close(); } - public interface ToFiniteStrings { - Set toFiniteStrings(TokenStream stream) throws IOException; + public static interface ToFiniteStrings { + public Set toFiniteStrings(TokenStream stream) throws IOException; } @Override @@ -130,4 +133,44 @@ public final class CompletionTokenStream extends TokenStream { CharSequence toUTF16(); } + + public static final class ByteTermAttributeImpl extends AttributeImpl implements ByteTermAttribute, TermToBytesRefAttribute { + private final BytesRefBuilder bytes = new BytesRefBuilder(); + private CharsRefBuilder charsRef; + + @Override + public BytesRefBuilder builder() { + return bytes; + } + + @Override + public BytesRef getBytesRef() { + return bytes.get(); + } + + @Override + public void clear() { + bytes.clear(); + } + + @Override + public void reflectWith(AttributeReflector reflector) { + + } + + @Override + public void copyTo(AttributeImpl target) { + ByteTermAttributeImpl other = (ByteTermAttributeImpl) target; + other.bytes.copyBytes(bytes); + } + + @Override + public CharSequence toUTF16() { + if (charsRef == null) { + charsRef = new CharsRefBuilder(); + } + charsRef.copyUTF8Bytes(getBytesRef()); + return charsRef.get(); + } + } }