diff --git a/extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/AnalyzerConfig.java b/extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/AnalyzerConfig.java index 1eb8af1c8dc..529dfdadb89 100644 --- a/extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/AnalyzerConfig.java +++ b/extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/AnalyzerConfig.java @@ -168,9 +168,9 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi // Classname is defined. // Probe class - Class clazz = null; + final Class untypedClazz; try { - clazz = Class.forName(className); + untypedClazz = Class.forName(className); } catch (ClassNotFoundException e) { LOG.error(String.format("Lucene index: analyzer class %s not found. (%s)", className, e.getMessage())); @@ -178,11 +178,13 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi } // CHeck if class is an Analyzer - if (!Analyzer.class.isAssignableFrom(clazz)) { + if (!Analyzer.class.isAssignableFrom(untypedClazz)) { LOG.error(String.format("Lucene index: analyzer class has to be a subclass of %s", Analyzer.class.getName())); return null; } + final Class clazz = (Class) untypedClazz; + // Get list of parameters List> cParams; try { @@ -216,7 +218,7 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi newAnalyzer = createInstance(clazz, cParamClasses, cParamValues, false); } else { - // Either no parameters have been provided or more than one parameter + // Either no parameters have been provided, or more than one parameter // Extend arrays with (default) Version object info, add to front. Class[] vcParamClasses = addVersionToClasses(cParamClasses); @@ -252,7 +254,7 @@ protected static Analyzer configureAnalyzer(Element config) throws DatabaseConfi * @param warnOnError true if an error should be treated as a warning * @return The lucene analyzer */ - private static Analyzer createInstance(final Class clazz, final Class[] vcParamClasses, + static T createInstance(final Class clazz, final Class[] vcParamClasses, final Object[] vcParamValues, final boolean warnOnError) { final String className = clazz.getName(); @@ -267,7 +269,7 @@ private static Analyzer createInstance(final Class clazz, final Class[] vc if (LOG.isDebugEnabled()) { LOG.debug(String.format("Using analyzer %s", className)); } - return (Analyzer)methodHandle.invokeWithArguments(vcParamValues); + return (T) methodHandle.invokeWithArguments(vcParamValues); } catch (final NoSuchMethodException e) { final String message = String.format("Could not find matching analyzer class constructor %s: %s", className, e.getMessage()); if (warnOnError) { @@ -318,7 +320,7 @@ private static Class[] addVersionToClasses(final Class[] cParamClasses) { * @return List of triples key-value-valueType * @throws org.exist.indexing.lucene.AnalyzerConfig.ParameterException */ - private static List> getAllConstructorParameters(Element config) throws ParameterException { + static List> getAllConstructorParameters(Element config) throws ParameterException { final List> parameters = new ArrayList<>(); final NodeList params = config.getElementsByTagNameNS(CollectionConfiguration.NAMESPACE, PARAM_ELEMENT_NAME); @@ -455,29 +457,43 @@ static KeyTypedValue getConstructorParameter(final Element param) throws Para } case "java.lang.Integer": - case "int": - if (value == null) { throw new ParameterException("The 'value' attribute must exist and must contain an integer value."); } - try { final Integer n = Integer.parseInt(value); parameter = new KeyTypedValue<>(name, n, Integer.class); - } catch (NumberFormatException ex) { + } catch (final NumberFormatException ex) { LOG.error(String.format("Value %s could not be converted to an integer. %s", value, ex.getMessage())); } break; + case "int": + if (value == null) { + throw new ParameterException("The 'value' attribute must exist and must contain an int value."); + } + try { + final Integer n = Integer.parseInt(value); + parameter = new KeyTypedValue<>(name, n.intValue(), int.class); + } catch (final NumberFormatException ex) { + LOG.error(String.format("Value %s could not be converted to an int. %s", value, ex.getMessage())); + } + break; + case "java.lang.Boolean": - case "boolean": + if (value == null) { + throw new ParameterException("The 'value' attribute must exist and must contain a Boolean value."); + } + final Boolean b1 = Boolean.parseBoolean(value); + parameter = new KeyTypedValue<>(name, b1, Boolean.class); + break; + case "boolean": if (value == null) { throw new ParameterException("The 'value' attribute must exist and must contain a boolean value."); } - - final boolean b = Boolean.parseBoolean(value); - parameter = new KeyTypedValue<>(name, b, boolean.class); + final Boolean b2 = Boolean.parseBoolean(value); + parameter = new KeyTypedValue<>(name, b2.booleanValue(), boolean.class); break; default: diff --git a/extensions/indexes/lucene/src/test/java/org/exist/indexing/lucene/AnalyzerConfigTest.java b/extensions/indexes/lucene/src/test/java/org/exist/indexing/lucene/AnalyzerConfigTest.java index 5dac759efe9..f9993ffcf49 100644 --- a/extensions/indexes/lucene/src/test/java/org/exist/indexing/lucene/AnalyzerConfigTest.java +++ b/extensions/indexes/lucene/src/test/java/org/exist/indexing/lucene/AnalyzerConfigTest.java @@ -21,6 +21,8 @@ */ package org.exist.indexing.lucene; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.util.Version; import org.exist.util.StringInputSource; import org.junit.Test; import org.w3c.dom.Document; @@ -31,9 +33,13 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.io.Reader; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * @author Adam Retter @@ -93,8 +99,512 @@ public void parameterFromStringArray() throws ParserConfigurationException, IOEx assertArrayEquals(new String[] {"hello", "hi", "", "goodbye"}, (String[])constructorParameter.getValue()); } + @Test + public void allParametersIntegerAndSet() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " \n" + + " '\n" + + " -\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(2, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("minimumTermLength", extractedConstructorArg1.getKey()); + assertEquals(Integer.class, extractedConstructorArg1.getValueClass()); + assertEquals(Integer.valueOf(2), extractedConstructorArg1.getValue()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg2 = extractedConstructorArgs.get(1); + assertEquals("punctuationDictionary", extractedConstructorArg2.getKey()); + assertEquals(Set.class, extractedConstructorArg2.getValueClass()); + assertTrue(extractedConstructorArg2.getValue() instanceof HashSet); + assertEquals(2, ((Set)extractedConstructorArg2.getValue()).size()); + } + + @Test + public void allParametersIntAndSet() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " \n" + + " '\n" + + " -\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(2, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("minimumTermLength", extractedConstructorArg1.getKey()); + assertEquals(int.class, extractedConstructorArg1.getValueClass()); + assertEquals(2, extractedConstructorArg1.getValue()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg2 = extractedConstructorArgs.get(1); + assertEquals("punctuationDictionary", extractedConstructorArg2.getKey()); + assertEquals(Set.class, extractedConstructorArg2.getValueClass()); + assertTrue(extractedConstructorArg2.getValue() instanceof HashSet); + assertEquals(2, ((Set)extractedConstructorArg2.getValue()).size()); + } + + @Test + public void allParametersBooleanAndSet() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " \n" + + " '\n" + + " -\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(2, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("minimumTermLength", extractedConstructorArg1.getKey()); + assertEquals(Boolean.class, extractedConstructorArg1.getValueClass()); + assertEquals(Boolean.TRUE, extractedConstructorArg1.getValue()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg2 = extractedConstructorArgs.get(1); + assertEquals("punctuationDictionary", extractedConstructorArg2.getKey()); + assertEquals(Set.class, extractedConstructorArg2.getValueClass()); + assertTrue(extractedConstructorArg2.getValue() instanceof HashSet); + assertEquals(2, ((Set)extractedConstructorArg2.getValue()).size()); + } + + @Test + public void allParametersPrimitiveBooleanAndSet() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " \n" + + " '\n" + + " -\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(2, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("minimumTermLength", extractedConstructorArg1.getKey()); + assertEquals(boolean.class, extractedConstructorArg1.getValueClass()); + assertEquals(true, extractedConstructorArg1.getValue()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg2 = extractedConstructorArgs.get(1); + assertEquals("punctuationDictionary", extractedConstructorArg2.getKey()); + assertEquals(Set.class, extractedConstructorArg2.getValueClass()); + assertTrue(extractedConstructorArg2.getValue() instanceof HashSet); + assertEquals(2, ((Set)extractedConstructorArg2.getValue()).size()); + } + + @Test + public void allParametersCharArray() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " '\n" + + " -\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(1, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("punctuationDictionary", extractedConstructorArg1.getKey()); + assertEquals(char[].class, extractedConstructorArg1.getValueClass()); + assertArrayEquals(new char[] {'\'', '-'}, (char[])extractedConstructorArg1.getValue()); + } + + @Test + public void allParametersStringArray() throws ParserConfigurationException, IOException, SAXException, AnalyzerConfig.ParameterException { + final String strAnalyzer = + "\n" + + " \n" + + " abc\n" + + " def\n" + + " \n" + + ""; + + final Element elemAnalyzer = parse(strAnalyzer).getDocumentElement(); + final List> extractedConstructorArgs = AnalyzerConfig.getAllConstructorParameters(elemAnalyzer); + + assertEquals(1, extractedConstructorArgs.size()); + + final AnalyzerConfig.KeyTypedValue extractedConstructorArg1 = extractedConstructorArgs.get(0); + assertEquals("punctuationDictionary", extractedConstructorArg1.getKey()); + assertEquals(String[].class, extractedConstructorArg1.getValueClass()); + assertArrayEquals(new String[] {"abc", "def"}, (String[])extractedConstructorArg1.getValue()); + } + + @Test + public void constructIntegerAndSetMockAnalyzerWithoutVersion() { + final Class analyerClass = IntegerAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Integer.class, + Set.class + }; + final Object[] vcParamValues = { + 12345, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final IntegerAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[0], mockAnalyzer.arg1); + assertEquals(vcParamValues[1], mockAnalyzer.arg2); + } + + @Test + public void constructIntegerAndSetMockAnalyzerWithVersion() { + final Class analyerClass = IntegerAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + Integer.class, + Set.class + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + 12345, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final IntegerAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[1], mockAnalyzer.arg1); + assertEquals(vcParamValues[2], mockAnalyzer.arg2); + } + + @Test + public void constructIntAndSetMockAnalyzerWithoutVersion() { + final Class analyerClass = IntAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + int.class, + Set.class + }; + final Object[] vcParamValues = { + 12345, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final IntAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[0], mockAnalyzer.arg1); + assertEquals(vcParamValues[1], mockAnalyzer.arg2); + } + + @Test + public void constructIntAndSetMockAnalyzerWithVersion() { + final Class analyerClass = IntAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + int.class, + Set.class + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + 12345, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final IntAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[1], mockAnalyzer.arg1); + assertEquals(vcParamValues[2], mockAnalyzer.arg2); + } + + @Test + public void constructBooleanAndSetMockAnalyzerWithoutVersion() { + final Class analyerClass = BooleanAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Boolean.class, + Set.class + }; + final Object[] vcParamValues = { + Boolean.TRUE, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final BooleanAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[0], mockAnalyzer.arg1); + assertEquals(vcParamValues[1], mockAnalyzer.arg2); + } + + @Test + public void constructBooleanAndSetMockAnalyzerWithVersion() { + final Class analyerClass = BooleanAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + Boolean.class, + Set.class + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + Boolean.TRUE, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final BooleanAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[1], mockAnalyzer.arg1); + assertEquals(vcParamValues[2], mockAnalyzer.arg2); + } + + @Test + public void constructPrimitiveAndSetMockAnalyzerWithoutVersion() { + final Class analyerClass = PrimitiveBooleanAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + boolean.class, + Set.class + }; + final Object[] vcParamValues = { + true, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final PrimitiveBooleanAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[0], mockAnalyzer.arg1); + assertEquals(vcParamValues[1], mockAnalyzer.arg2); + } + + @Test + public void constructPrimitiveBooleanAndSetMockAnalyzerWithVersion() { + final Class analyerClass = PrimitiveBooleanAndSetConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + boolean.class, + Set.class + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + true, + new HashSet<>(Arrays.asList("s1, s2")) + }; + + final PrimitiveBooleanAndSetConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertEquals(vcParamValues[1], mockAnalyzer.arg1); + assertEquals(vcParamValues[2], mockAnalyzer.arg2); + } + + @Test + public void constructCharArrayMockAnalyzerWithoutVersion() { + final Class analyerClass = CharArrayConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + char[].class, + }; + final Object[] vcParamValues = { + new char[] {'\'', '-'} + }; + + final CharArrayConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertArrayEquals((char[])vcParamValues[0], mockAnalyzer.arg1); + } + + @Test + public void constructCharArrayMockAnalyzerWithVersion() { + final Class analyerClass = CharArrayConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + char[].class, + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + new char[] {'\'', '-'} + }; + + final CharArrayConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertArrayEquals((char[])vcParamValues[1], mockAnalyzer.arg1); + } + + @Test + public void constructStringArrayMockAnalyzerWithoutVersion() { + final Class analyerClass = StringArrayConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + String[].class, + }; + final Object[] vcParamValues = { + new String[] {"abc", "def"} + }; + + final StringArrayConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertNull(mockAnalyzer.luceneVersion); + assertArrayEquals((String[])vcParamValues[0], mockAnalyzer.arg1); + } + + @Test + public void constructStringArrayMockAnalyzerWithVersion() { + final Class analyerClass = StringArrayConstructorMockAnalyzer.class; + final Class[] vcParamClasses = new Class[] { + Version.class, + String[].class, + }; + final Object[] vcParamValues = { + LuceneIndex.LUCENE_VERSION_IN_USE, + new String[] {"abc", "def"} + }; + + final StringArrayConstructorMockAnalyzer mockAnalyzer = AnalyzerConfig.createInstance(analyerClass, vcParamClasses, vcParamValues, true); + assertNotNull(mockAnalyzer); + assertEquals(vcParamValues[0], mockAnalyzer.luceneVersion); + assertArrayEquals((String[])vcParamValues[1], mockAnalyzer.arg1); + } + private Document parse(final String strXml) throws ParserConfigurationException, IOException, SAXException { final DocumentBuilder documentBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder(); return documentBuilder.parse(new StringInputSource(strXml)); } + + static class IntegerAndSetConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final Integer arg1; + final Set arg2; + + public IntegerAndSetConstructorMockAnalyzer(final Integer arg1, final Set arg2) { + this(null, arg1, arg2); + } + + public IntegerAndSetConstructorMockAnalyzer(final Version luceneVersion, final Integer arg1, final Set arg2) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + this.arg2 = arg2; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } + + static class IntAndSetConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final int arg1; + final Set arg2; + + public IntAndSetConstructorMockAnalyzer(final int arg1, final Set arg2) { + this(null, arg1, arg2); + } + + public IntAndSetConstructorMockAnalyzer(final Version luceneVersion, final int arg1, final Set arg2) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + this.arg2 = arg2; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } + + static class BooleanAndSetConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final Boolean arg1; + final Set arg2; + + public BooleanAndSetConstructorMockAnalyzer(final Boolean arg1, final Set arg2) { + this(null, arg1, arg2); + } + + public BooleanAndSetConstructorMockAnalyzer(final Version luceneVersion, final Boolean arg1, final Set arg2) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + this.arg2 = arg2; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } + + static class PrimitiveBooleanAndSetConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final boolean arg1; + final Set arg2; + + public PrimitiveBooleanAndSetConstructorMockAnalyzer(final boolean arg1, final Set arg2) { + this(null, arg1, arg2); + } + + public PrimitiveBooleanAndSetConstructorMockAnalyzer(final Version luceneVersion, final boolean arg1, final Set arg2) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + this.arg2 = arg2; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } + + static class CharArrayConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final char[] arg1; + + public CharArrayConstructorMockAnalyzer(final char[] arg1) { + this(null, arg1); + } + + public CharArrayConstructorMockAnalyzer(final Version luceneVersion, final char[] arg1) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } + + static class StringArrayConstructorMockAnalyzer extends Analyzer { + final Version luceneVersion; + final String[] arg1; + + public StringArrayConstructorMockAnalyzer(final String[] arg1) { + this(null, arg1); + } + + public StringArrayConstructorMockAnalyzer(final Version luceneVersion, final String[] arg1) { + this.luceneVersion = luceneVersion; + this.arg1 = arg1; + } + + @Override + protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) { + throw new UnsupportedOperationException("This analyzer is a mock for testing"); + } + } }