From 61e45283061ae486acc5882c5a770025c8291222 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Mon, 9 Jan 2017 14:59:31 +0100 Subject: [PATCH] add test that EdgeNGram filter keeps payloads --- .../analysis/ngram/TestNGramFilters.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/TestNGramFilters.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/TestNGramFilters.java index 12433526f6e..b6f4405555f 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/TestNGramFilters.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/ngram/TestNGramFilters.java @@ -22,7 +22,10 @@ import java.io.StringReader; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.payloads.PayloadHelper; +import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; import org.apache.lucene.analysis.util.BaseTokenStreamFactoryTestCase; +import org.apache.lucene.util.BytesRef; /** * Simple tests to ensure the NGram filter factories are working. @@ -123,6 +126,25 @@ public class TestNGramFilters extends BaseTokenStreamFactoryTestCase { assertTokenStreamContents(stream, new String[] { "t", "te" }); } + + public void testEdgeNGramFilterPayload() throws Exception { + Reader reader = new StringReader("test|0.1"); + TokenStream stream = whitespaceMockTokenizer(reader); + stream = tokenFilterFactory("DelimitedPayload", "encoder", "float").create(stream); + stream = tokenFilterFactory("EdgeNGram", "minGramSize", "1", "maxGramSize", "2").create(stream); + + stream.reset(); + while (stream.incrementToken()) { + PayloadAttribute payAttr = stream.getAttribute(PayloadAttribute.class); + assertNotNull(payAttr); + BytesRef payData = payAttr.getPayload(); + assertNotNull(payData); + float payFloat = PayloadHelper.decodeFloat(payData.bytes); + assertEquals(0.1f, payFloat, 0.0f); + } + stream.end(); + stream.close(); + } /** Test that bogus arguments result in exception */ public void testBogusArguments() throws Exception {