SchemaAnalyzer extends DelegatingAnalyzerWrapper { protected static Analyzer getAnalyzer(Map<String, Analyzer> analyzers, String name) { if (StringUtils.isBlank(name)) { throw new IndexException("Not empty analyzer name required"); } Analyzer analyzer = analyzers.get(name); if (analyzer == null) { analyzer = StandardAnalyzers.get(name); if (analyzer == null) { try { analyzer = (new ClasspathAnalyzerBuilder(name)).analyzer(); } catch (Exception e) { throw new IndexException(e, "Not found analyzer '{}'", name); } } } return analyzer; } SchemaAnalyzer(Analyzer defaultAnalyzer, Map<String, Analyzer> analyzers, Map<String, Mapper> mappers); TokenLengthAnalyzer getDefaultAnalyzer(); TokenLengthAnalyzer getAnalyzer(String fieldName); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testGetAnalyzerNull() { Analyzer defaultAnalyzer = new EnglishAnalyzer(); Map<String, Mapper> mappers = new HashMap<>(); Map<String, Analyzer> analyzers = new HashMap<>(); SchemaAnalyzer schemaAnalyzer = new SchemaAnalyzer(defaultAnalyzer, analyzers, mappers); schemaAnalyzer.getAnalyzer(null); }
@Test(expected = IllegalArgumentException.class) public void testGetAnalyzerBlank() { Analyzer defaultAnalyzer = new EnglishAnalyzer(); Map<String, Mapper> mappers = new HashMap<>(); Map<String, Analyzer> analyzers = new HashMap<>(); SchemaAnalyzer schemaAnalyzer = new SchemaAnalyzer(defaultAnalyzer, analyzers, mappers); schemaAnalyzer.getAnalyzer(" \t"); }
@Test public void testGetAnalyzerNotExistent() { Analyzer defaultAnalyzer = new EnglishAnalyzer(); Map<String, Mapper> mappers = new HashMap<>(); Map<String, Analyzer> analyzers = new HashMap<>(); SchemaAnalyzer schemaAnalyzer = new SchemaAnalyzer(defaultAnalyzer, analyzers, mappers); schemaAnalyzer.getAnalyzer("failing"); }
@Test public void testStaticGetAnalyzer() { Analyzer expectedAnalyzer = new EnglishAnalyzer(); Map<String, Analyzer> analyzers = new HashMap<>(); analyzers.put("analyzer", expectedAnalyzer); Analyzer actualAnalyzer = SchemaAnalyzer.getAnalyzer(analyzers, "analyzer"); assertEquals("Static get analyzer is failing", expectedAnalyzer, actualAnalyzer); }
@Test(expected = IndexException.class) public void testStaticGetAnalyzerBlank() { Map<String, Analyzer> analyzers = new HashMap<>(); SchemaAnalyzer.getAnalyzer(analyzers, " "); }
@Test(expected = IndexException.class) public void testStaticGetAnalyzerNotExistent() { Map<String, Analyzer> analyzers = new HashMap<>(); SchemaAnalyzer.getAnalyzer(analyzers, "non-existent"); }