Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Deprecated superfluous abstract getTerms method introduced in SpanQuery.java, added implementations of Query's existing extractTerms method and switched SpanWeight to use extractTerms instead.

Mark Harwood4696ac421e40
diff --git a/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java b/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
index dde4fb47a0e..422ad8c4b1c 100644
--- a/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
@@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
import java.util.Collection;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
@@ -44,6 +45,10 @@ public class SpanFirstQuery extends SpanQuery {
public String getField() { return match.getField(); }
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see #extractTerms(Set)
+ */
public Collection getTerms() { return match.getTerms(); }
public String toString(String field) {
@@ -56,6 +61,10 @@ public class SpanFirstQuery extends SpanQuery {
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
+
+ public void extractTerms(Set terms) {
+ match.extractTerms(terms);
+ }
public Spans getSpans(final IndexReader reader) throws IOException {
return new Spans() {
diff --git a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
index 01816a26c8a..4da21d108ba 100644
--- a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
@@ -72,7 +73,11 @@ public class SpanNearQuery extends SpanQuery {
public boolean isInOrder() { return inOrder; }
public String getField() { return field; }
-
+
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see #extractTerms(Set)
+ */
public Collection getTerms() {
Collection terms = new ArrayList();
Iterator i = clauses.iterator();
@@ -82,6 +87,15 @@ public class SpanNearQuery extends SpanQuery {
}
return terms;
}
+
+ public void extractTerms(Set terms) {
+ Iterator i = clauses.iterator();
+ while (i.hasNext()) {
+ SpanQuery clause = (SpanQuery)i.next();
+ clause.extractTerms(terms);
+ }
+ }
+
public String toString(String field) {
StringBuffer buffer = new StringBuffer();
diff --git a/src/java/org/apache/lucene/search/spans/SpanNotQuery.java b/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
index e3bc4c6dba2..72f4be8d053 100644
--- a/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
@@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
import java.util.Collection;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
@@ -47,7 +48,13 @@ public class SpanNotQuery extends SpanQuery {
public String getField() { return include.getField(); }
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see #extractTerms(Set)
+ */
public Collection getTerms() { return include.getTerms(); }
+
+ public void extractTerms(Set terms) { include.extractTerms(terms); }
public String toString(String field) {
StringBuffer buffer = new StringBuffer();
diff --git a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java b/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
index 1b7aa07ebd7..eb3539324a7 100644
--- a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.PriorityQueue;
@@ -56,6 +57,10 @@ public class SpanOrQuery extends SpanQuery {
public String getField() { return field; }
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see #extractTerms(Set)
+ */
public Collection getTerms() {
Collection terms = new ArrayList();
Iterator i = clauses.iterator();
@@ -65,6 +70,15 @@ public class SpanOrQuery extends SpanQuery {
}
return terms;
}
+
+ public void extractTerms(Set terms) {
+ Iterator i = clauses.iterator();
+ while (i.hasNext()) {
+ SpanQuery clause = (SpanQuery)i.next();
+ clause.extractTerms(terms);
+ }
+ }
+
public Query rewrite(IndexReader reader) throws IOException {
SpanOrQuery clone = null;
diff --git a/src/java/org/apache/lucene/search/spans/SpanQuery.java b/src/java/org/apache/lucene/search/spans/SpanQuery.java
index 527f6bdc781..935a7ee056d 100644
--- a/src/java/org/apache/lucene/search/spans/SpanQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanQuery.java
@@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
import java.util.Collection;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
@@ -34,7 +35,10 @@ public abstract class SpanQuery extends Query {
/** Returns the name of the field matched by this query.*/
public abstract String getField();
- /** Returns a collection of all terms matched by this query.*/
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see Query#extractTerms(Set)
+ */
public abstract Collection getTerms();
protected Weight createWeight(Searcher searcher) throws IOException {
diff --git a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
index fe1ad6b781f..7a39b32b55a 100644
--- a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.ArrayList;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
@@ -37,12 +38,19 @@ public class SpanTermQuery extends SpanQuery {
public Term getTerm() { return term; }
public String getField() { return term.field(); }
-
+
+ /** Returns a collection of all terms matched by this query.
+ * @deprecated use extractTerms instead
+ * @see #extractTerms(Set)
+ */
public Collection getTerms() {
Collection terms = new ArrayList();
terms.add(term);
return terms;
}
+ public void extractTerms(Set terms) {
+ terms.add(term);
+ }
public String toString(String field) {
StringBuffer buffer = new StringBuffer();
diff --git a/src/java/org/apache/lucene/search/spans/SpanWeight.java b/src/java/org/apache/lucene/search/spans/SpanWeight.java
index c81190c9066..58452d9791b 100644
--- a/src/java/org/apache/lucene/search/spans/SpanWeight.java
+++ b/src/java/org/apache/lucene/search/spans/SpanWeight.java
@@ -18,8 +18,9 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.Collection;
+import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
@@ -38,14 +39,15 @@ class SpanWeight implements Weight {
private float queryNorm;
private float queryWeight;
- private Collection terms;
+ private Set terms;
private SpanQuery query;
public SpanWeight(SpanQuery query, Searcher searcher)
throws IOException {
this.similarity = query.getSimilarity(searcher);
this.query = query;
- this.terms = query.getTerms();
+ terms=new HashSet();
+ query.extractTerms(terms);
idf = this.query.getSimilarity(searcher).idf(terms, searcher);
}