From 9f7f76f267bd46b0069731ba1ae4990d31c33df8 Mon Sep 17 00:00:00 2001 From: David Smiley Date: Tue, 19 Dec 2017 10:28:22 -0500 Subject: [PATCH] LUCENE-5803: Add a Solr test that we reuse analysis components across fields for the same field type --- .../miscellaneous/TestPerFieldAnalyzerWrapper.java | 2 ++ .../org/apache/solr/schema/IndexSchemaTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java index 903076d68fd..54a64cef021 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java @@ -88,7 +88,9 @@ public class TestPerFieldAnalyzerWrapper extends BaseTokenStreamTestCase { // test that the PerFieldWrapper returns the same instance as original Analyzer: ts1 = defaultAnalyzer.tokenStream("something", text); ts2 = wrapper1.tokenStream("something", text); + ts3 = wrapper1.tokenStream("somethingElse", text); assertSame(ts1, ts2); + assertSame(ts2, ts3); ts1 = specialAnalyzer.tokenStream("special", text); ts2 = wrapper1.tokenStream("special", text); diff --git a/solr/core/src/test/org/apache/solr/schema/IndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/IndexSchemaTest.java index 4719f0408fb..6bfa14fe27f 100644 --- a/solr/core/src/test/org/apache/solr/schema/IndexSchemaTest.java +++ b/solr/core/src/test/org/apache/solr/schema/IndexSchemaTest.java @@ -17,6 +17,8 @@ package org.apache.solr.schema; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.TokenStream; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.MapSolrParams; @@ -115,4 +117,16 @@ public class IndexSchemaTest extends SolrTestCaseJ4 { 6, ((TrieDateField)tdatedv).getPrecisionStep()); } } + + @Test // LUCENE-5803 + public void testReuseAnalysisComponents() throws Exception { + IndexSchema schema = h.getCore().getLatestSchema(); + Analyzer solrAnalyzer = schema.getIndexAnalyzer(); + // Get the tokenStream for two fields that both have the same field type (name "text") + TokenStream ts1 = solrAnalyzer.tokenStream("text", "foo bar"); // a non-dynamic field + TokenStream ts2 = solrAnalyzer.tokenStream("t_text", "whatever"); // a dynamic field + assertSame(ts1, ts2); + ts1.close(); + ts2.close(); + } }