LUCENE-5803: Add a Solr test that we reuse analysis components across fields for the same field type

This commit is contained in:
David Smiley 2017-12-19 10:28:22 -05:00
parent 79073fafd3
commit 9f7f76f267
2 changed files with 16 additions and 0 deletions

View File

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

View File

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