You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by rm...@apache.org on 2010/02/21 08:00:08 UTC
svn commit: r912308 - in /lucene/java/trunk/contrib/benchmark: CHANGES.txt
src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java
src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java
Author: rmuir
Date: Sun Feb 21 07:00:08 2010
New Revision: 912308
URL: http://svn.apache.org/viewvc?rev=912308&view=rev
Log:
LUCENE-2254: add support to quality pkg for any combination of (title,description,narrative)
Modified:
lucene/java/trunk/contrib/benchmark/CHANGES.txt
lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java
lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java
Modified: lucene/java/trunk/contrib/benchmark/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/CHANGES.txt?rev=912308&r1=912307&r2=912308&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/benchmark/CHANGES.txt Sun Feb 21 07:00:08 2010
@@ -2,6 +2,11 @@
The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways.
+2/21/2020
+ LUCENE-2254: Add support to the quality package for running
+ experiments with any combination of Title, Description, and Narrative.
+ (Robert Muir)
+
1/28/2010
LUCENE-2223: Add a benchmark for ShingleFilter. You can wrap any
analyzer with ShingleAnalyzerWrapper and specify shingle parameters
Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java?rev=912308&r1=912307&r2=912308&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java Sun Feb 21 07:00:08 2010
@@ -30,6 +30,8 @@
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Set;
/**
@@ -38,12 +40,14 @@
**/
public class QueryDriver {
public static void main(String[] args) throws Exception {
- if (args.length != 4) {
- System.err.println("Usage: QueryDriver <topicsFile> <qrelsFile> <submissionFile> <indexDir>");
+ if (args.length < 4 || args.length > 5) {
+ System.err.println("Usage: QueryDriver <topicsFile> <qrelsFile> <submissionFile> <indexDir> [querySpec]");
System.err.println("topicsFile: input file containing queries");
System.err.println("qrelsFile: input file containing relevance judgements");
System.err.println("submissionFile: output submission file for trec_eval");
System.err.println("indexDir: index directory");
+ System.err.println("querySpec: string composed of fields to use in query consisting of T=title,D=description,N=narrative:");
+ System.err.println("\texample: TD (query on Title + Description). The default is T (title only)");
System.exit(1);
}
@@ -51,6 +55,7 @@
File qrelsFile = new File(args[1]);
SubmissionReport submitLog = new SubmissionReport(new PrintWriter(args[2]), "lucene");
FSDirectory dir = FSDirectory.open(new File(args[3]));
+ String fieldSpec = args.length == 5 ? args[4] : "T"; // default to Title-only if not specified.
Searcher searcher = new IndexSearcher(dir, true);
int maxResults = 1000;
@@ -68,8 +73,13 @@
// validate topics & judgments match each other
judge.validateData(qqs, logger);
+ Set<String> fieldSet = new HashSet<String>();
+ if (fieldSpec.indexOf('T') >= 0) fieldSet.add("title");
+ if (fieldSpec.indexOf('D') >= 0) fieldSet.add("description");
+ if (fieldSpec.indexOf('N') >= 0) fieldSet.add("narrative");
+
// set the parsing of quality queries into Lucene queries.
- QualityQueryParser qqParser = new SimpleQQParser("title", "body");
+ QualityQueryParser qqParser = new SimpleQQParser(fieldSet.toArray(new String[0]), "body");
// run the benchmark
QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);
Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java?rev=912308&r1=912307&r2=912308&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/SimpleQQParser.java Sun Feb 21 07:00:08 2010
@@ -21,27 +21,38 @@
import org.apache.lucene.benchmark.quality.QualityQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;
/**
* Simplistic quality query parser. A Lucene query is created by passing
- * the value of the specified QualityQuery name-value pair into
+ * the value of the specified QualityQuery name-value pair(s) into
* a Lucene's QueryParser using StandardAnalyzer. */
public class SimpleQQParser implements QualityQueryParser {
- private String qqName;
+ private String qqNames[];
private String indexField;
ThreadLocal<QueryParser> queryParser = new ThreadLocal<QueryParser>();
/**
* Constructor of a simple qq parser.
+ * @param qqName name-value pairs of quality query to use for creating the query
+ * @param indexField corresponding index field
+ */
+ public SimpleQQParser(String qqNames[], String indexField) {
+ this.qqNames = qqNames;
+ this.indexField = indexField;
+ }
+
+ /**
+ * Constructor of a simple qq parser.
* @param qqName name-value pair of quality query to use for creating the query
* @param indexField corresponding index field
*/
public SimpleQQParser(String qqName, String indexField) {
- this.qqName = qqName;
- this.indexField = indexField;
+ this(new String[] { qqName }, indexField);
}
/* (non-Javadoc)
@@ -53,7 +64,11 @@
qp = new QueryParser(Version.LUCENE_CURRENT, indexField, new StandardAnalyzer(Version.LUCENE_CURRENT));
queryParser.set(qp);
}
- return qp.parse(qq.getValue(qqName));
+ BooleanQuery bq = new BooleanQuery();
+ for (int i = 0; i < qqNames.length; i++)
+ bq.add(qp.parse(QueryParser.escape(qq.getValue(qqNames[i]))), BooleanClause.Occur.SHOULD);
+
+ return bq;
}
}