Index: Query.java
===================================================================
--- Query.java (revision 164732)
+++ Query.java (working copy)
@@ -104,16 +104,41 @@
/** Expert: called when re-writing queries under MultiSearcher.
*
- *
Only implemented by derived queries, with no
- * {@link #createWeight(Searcher)} implementatation.
+ * Create a single query suitable for use by all subsearchers (in 1-1
+ * correspondence with queries). This is an optimization of the OR of
+ * all queries. We handle the common optimization cases of equal
+ * queries and overlapping clauses of boolean OR queries (as generated
+ * by MultiTermQuery.rewrite() and RangeQuery.rewrite()).
+ * Be careful overriding this method as queries[0] determines which
+ * method will be called and is not necessarily of the same type as
+ * the other queries.
*/
public Query combine(Query[] queries) {
- for (int i = 0; i < queries.length; i++) {
- if (!this.equals(queries[i])) {
- throw new IllegalArgumentException();
+ HashSet uniques = new HashSet();
+ nextquery: for (int i=0; iA utility for use by {@link #combine(Query[])} implementations.
- */
- public static Query mergeBooleanQueries(Query[] queries) {
- HashSet allClauses = new HashSet();
- for (int i = 0; i < queries.length; i++) {
- BooleanClause[] clauses = ((BooleanQuery)queries[i]).getClauses();
- for (int j = 0; j < clauses.length; j++) {
- allClauses.add(clauses[j]);
- }
- }
-
- boolean coordDisabled =
- queries.length==0? false : ((BooleanQuery)queries[0]).isCoordDisabled();
- BooleanQuery result = new BooleanQuery(coordDisabled);
- Iterator i = allClauses.iterator();
- while (i.hasNext()) {
- result.add((BooleanClause)i.next());
- }
- return result;
- }
-
/** Expert: Returns the Similarity implementation to be used for this query.
* Subclasses may override this method to specify their own Similarity
* implementation, perhaps one that delegates through that of the Searcher.
Index: BooleanQuery.java
===================================================================
--- BooleanQuery.java (revision 164732)
+++ BooleanQuery.java (working copy)
@@ -371,11 +371,6 @@
}
}
- // inherit javadoc
- public Query combine(Query[] queries) {
- return Query.mergeBooleanQueries(queries);
- }
-
public Object clone() {
BooleanQuery clone = (BooleanQuery)super.clone();
clone.clauses = (Vector)this.clauses.clone();
Index: RangeQuery.java
===================================================================
--- RangeQuery.java (revision 164732)
+++ RangeQuery.java (working copy)
@@ -104,10 +104,6 @@
return query;
}
- public Query combine(Query[] queries) {
- return Query.mergeBooleanQueries(queries);
- }
-
/** Returns the field name for this query */
public String getField() {
return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
Index: MultiTermQuery.java
===================================================================
--- MultiTermQuery.java (revision 164732)
+++ MultiTermQuery.java (working copy)
@@ -67,11 +67,6 @@
return query;
}
- public Query combine(Query[] queries) {
- return Query.mergeBooleanQueries(queries);
- }
-
-
/** Prints a user-readable version of this query. */
public String toString(String field) {
StringBuffer buffer = new StringBuffer();
Index: PrefixQuery.java
===================================================================
--- PrefixQuery.java (revision 164732)
+++ PrefixQuery.java (working copy)
@@ -59,10 +59,6 @@
return query;
}
- public Query combine(Query[] queries) {
- return Query.mergeBooleanQueries(queries);
- }
-
/** Prints a user-readable version of this query. */
public String toString(String field) {
StringBuffer buffer = new StringBuffer();