Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Add support for LongToEnglish doc/query maker

Grant Ingersoll36beb9e05934
diff --git a/contrib/benchmark/build.xml b/contrib/benchmark/build.xml
index 1eb7de389b5..6c283afa4f0 100644
--- a/contrib/benchmark/build.xml
+++ b/contrib/benchmark/build.xml
@@ -104,6 +104,7 @@
<path id="classpath">
<pathelement path="${common.dir}/build/classes/java"/>
<pathelement path="${common.dir}/build/classes/demo"/>
+ <pathelement path="${common.dir}/build/classes/test"/>
<pathelement path="${common.dir}/build/contrib/highlighter/classes/java"/>
<pathelement path="${common.dir}/build/contrib/memory/classes/java"/>
<pathelement path="${common.dir}/build/contrib/fast-vector-highlighter/classes/java"/>
@@ -120,7 +121,7 @@
<property name="task.alg" location="conf/micro-standard.alg"/>
<property name="task.mem" value="140M"/>
- <target name="run-task" depends="compile,check-files,get-files"
+ <target name="run-task" depends="compile-test,check-files,get-files"
description="Run compound penalty perf test (optional: -Dtask.alg=your-algorithm-file -Dtask.mem=java-max-mem)">
<echo>Working Directory: ${working.dir}</echo>
<java classname="org.apache.lucene.benchmark.byTask.Benchmark" maxmemory="${task.mem}" fork="true">
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java
new file mode 100644
index 00000000000..d2292655483
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java
@@ -0,0 +1,37 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+
+import org.apache.lucene.util.English;
+
+import java.io.IOException;
+import java.util.Date;
+
+
+/**
+ *
+ *
+ **/
+public class LongToEnglishContentSource extends ContentSource{
+ private long counter = Long.MIN_VALUE + 10;
+
+ public void close() throws IOException {
+
+ }
+ //TODO: reduce/clean up synchonization
+ public synchronized DocData getNextDocData(DocData docData) throws NoMoreDataException, IOException {
+ docData.clear();
+ docData.setBody(English.longToEnglish(counter));
+ docData.setName("doc_" + String.valueOf(counter));
+ docData.setTitle("title_" + String.valueOf(counter));
+ docData.setDate(new Date());
+ if (counter == Long.MAX_VALUE){
+ counter = Long.MIN_VALUE + 10;//loop around
+ }
+ counter++;
+ return docData;
+ }
+
+ @Override
+ public void resetInputs() throws IOException {
+ counter = Long.MIN_VALUE + 10;
+ }
+}
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java
new file mode 100644
index 00000000000..6abe9fcccd9
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java
@@ -0,0 +1,49 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.benchmark.byTask.tasks.NewAnalyzerTask;
+import org.apache.lucene.benchmark.byTask.utils.Config;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.util.English;
+import org.apache.lucene.util.Version;
+
+
+/**
+ *
+ *
+ **/
+public class LongToEnglishQueryMaker implements QueryMaker {
+ long counter = Long.MIN_VALUE + 10;
+ protected QueryParser parser;
+
+ public Query makeQuery(int size) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ public synchronized Query makeQuery() throws Exception {
+
+ return parser.parse("" + English.longToEnglish(getNextCounter()) + "");
+ }
+
+ private synchronized long getNextCounter() {
+ if (counter == Long.MAX_VALUE){
+ counter = Long.MIN_VALUE + 10;
+ }
+ return counter++;
+ }
+
+ public void setConfig(Config config) throws Exception {
+ Analyzer anlzr = NewAnalyzerTask.createAnalyzer(config.get("analyzer", StandardAnalyzer.class.getName()));
+ parser = new QueryParser(Version.LUCENE_CURRENT, DocMaker.BODY_FIELD, anlzr);
+ }
+
+ public void resetInputs() {
+ counter = Long.MIN_VALUE + 10;
+ }
+
+ public String printQueries() {
+ return "LongToEnglish: [" + Long.MIN_VALUE + " TO " + counter + "]";
+ }
+}