Removed special case for looking up KeywordAnalyzer, which is *not* alone among analyzers occupying package o.a.l.analysis.core.

Instead, now attempting to instantiate no-package analyzers as core analyzers, then falling back to the previous default package ("org.apache.lucene.analysis.") if that fails.  Also, made the same changes in NewShingleAnalyzerTask.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1087468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2011-03-31 22:34:46 +00:00
parent 4997068dc5
commit 9cefe60a4b
2 changed files with 39 additions and 30 deletions

View File

@ -20,9 +20,7 @@ import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.StringTokenizer;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
/** /**
@ -58,15 +56,28 @@ public class NewAnalyzerTask extends PerfTask {
current = 0; current = 0;
} }
className = analyzerClassNames.get(current++); className = analyzerClassNames.get(current++);
if (className == null || className.equals("")) { Analyzer analyzer = null;
if (null == className || 0 == className.length()) {
className = "org.apache.lucene.analysis.standard.StandardAnalyzer"; className = "org.apache.lucene.analysis.standard.StandardAnalyzer";
} else if (className.equals("KeywordAnalyzer")) {
className = "org.apache.lucene.analysis.core.KeywordAnalyzer";
} else if (className.indexOf(".") == -1 || className.startsWith("standard.")) {
//there is no package name, assume o.a.l.analysis
className = "org.apache.lucene.analysis." + className;
} }
getRunData().setAnalyzer(createAnalyzer(className)); if (-1 == className.indexOf(".")) {
try {
// If no package, first attempt to instantiate a core analyzer
String coreClassName = "org.apache.lucene.analysis.core." + className;
analyzer = createAnalyzer(coreClassName);
className = coreClassName;
} catch (ClassNotFoundException e) {
// If not a core analyzer, try the base analysis package
className = "org.apache.lucene.analysis." + className;
analyzer = createAnalyzer(className);
}
} else {
if (className.startsWith("standard.")) {
className = "org.apache.lucene.analysis." + className;
}
analyzer = createAnalyzer(className);
}
getRunData().setAnalyzer(analyzer);
System.out.println("Changed Analyzer to: " + className); System.out.println("Changed Analyzer to: " + className);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error creating Analyzer: " + className, e); throw new RuntimeException("Error creating Analyzer: " + className, e);

View File

@ -17,13 +17,11 @@ package org.apache.lucene.benchmark.byTask.tasks;
* limitations under the License. * limitations under the License.
*/ */
import java.lang.reflect.Constructor;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.shingle.ShingleAnalyzerWrapper; import org.apache.lucene.analysis.shingle.ShingleAnalyzerWrapper;
import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.util.Version;
/** /**
* Task to support benchmarking ShingleFilter / ShingleAnalyzerWrapper * Task to support benchmarking ShingleFilter / ShingleAnalyzerWrapper
@ -45,26 +43,26 @@ public class NewShingleAnalyzerTask extends PerfTask {
} }
private void setAnalyzer() throws Exception { private void setAnalyzer() throws Exception {
Class<? extends Analyzer> clazz = null; Analyzer wrappedAnalyzer = null;
Analyzer wrappedAnalyzer; if (null == analyzerClassName || 0 == analyzerClassName.length()) {
try { analyzerClassName = "org.apache.lucene.analysis.standard.StandardAnalyzer";
if (analyzerClassName == null || analyzerClassName.equals("")) { }
analyzerClassName if (-1 == analyzerClassName.indexOf(".")) {
= "org.apache.lucene.analysis.standard.StandardAnalyzer"; String coreClassName = "org.apache.lucene.analysis.core." + analyzerClassName;
try {
// If there is no package, first attempt to instantiate a core analyzer
wrappedAnalyzer = NewAnalyzerTask.createAnalyzer(coreClassName);
analyzerClassName = coreClassName;
} catch (ClassNotFoundException e) {
// If this is not a core analyzer, try the base analysis package
analyzerClassName = "org.apache.lucene.analysis." + analyzerClassName;
wrappedAnalyzer = NewAnalyzerTask.createAnalyzer(analyzerClassName);
} }
if (analyzerClassName.indexOf(".") == -1 } else {
|| analyzerClassName.startsWith("standard.")) { if (analyzerClassName.startsWith("standard.")) {
//there is no package name, assume o.a.l.analysis
analyzerClassName = "org.apache.lucene.analysis." + analyzerClassName; analyzerClassName = "org.apache.lucene.analysis." + analyzerClassName;
} }
clazz = Class.forName(analyzerClassName).asSubclass(Analyzer.class); wrappedAnalyzer = NewAnalyzerTask.createAnalyzer(analyzerClassName);
// first try to use a ctor with version parameter (needed for many new
// Analyzers that have no default one anymore)
Constructor<? extends Analyzer> ctor = clazz.getConstructor(Version.class);
wrappedAnalyzer = ctor.newInstance(Version.LUCENE_CURRENT);
} catch (NoSuchMethodException e) {
// otherwise use default ctor
wrappedAnalyzer = clazz.newInstance();
} }
ShingleAnalyzerWrapper analyzer ShingleAnalyzerWrapper analyzer
= new ShingleAnalyzerWrapper(wrappedAnalyzer, maxShingleSize); = new ShingleAnalyzerWrapper(wrappedAnalyzer, maxShingleSize);
@ -77,7 +75,7 @@ public class NewShingleAnalyzerTask extends PerfTask {
try { try {
setAnalyzer(); setAnalyzer();
System.out.println System.out.println
("Changed Analyzer to: ShingleAnalyzerWrapper, wrapping ShingleFilter over" ("Changed Analyzer to: ShingleAnalyzerWrapper, wrapping ShingleFilter over "
+ analyzerClassName); + analyzerClassName);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error creating Analyzer", e); throw new RuntimeException("Error creating Analyzer", e);