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

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@389886 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Harwood 2006-03-29 20:50:47 +00:00
parent bb923a20b1
commit 4696ac421e
7 changed files with 64 additions and 6 deletions

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
@ -44,6 +45,10 @@ public class SpanFirstQuery extends SpanQuery {
public String getField() { return match.getField(); } 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 Collection getTerms() { return match.getTerms(); }
public String toString(String field) { public String toString(String field) {
@ -56,6 +61,10 @@ public class SpanFirstQuery extends SpanQuery {
buffer.append(ToStringUtils.boost(getBoost())); buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString(); return buffer.toString();
} }
public void extractTerms(Set terms) {
match.extractTerms(terms);
}
public Spans getSpans(final IndexReader reader) throws IOException { public Spans getSpans(final IndexReader reader) throws IOException {
return new Spans() { return new Spans() {

View File

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
@ -72,7 +73,11 @@ public class SpanNearQuery extends SpanQuery {
public boolean isInOrder() { return inOrder; } public boolean isInOrder() { return inOrder; }
public String getField() { return field; } 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() { public Collection getTerms() {
Collection terms = new ArrayList(); Collection terms = new ArrayList();
Iterator i = clauses.iterator(); Iterator i = clauses.iterator();
@ -82,6 +87,15 @@ public class SpanNearQuery extends SpanQuery {
} }
return terms; 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) { public String toString(String field) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
@ -47,7 +48,13 @@ public class SpanNotQuery extends SpanQuery {
public String getField() { return include.getField(); } 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 Collection getTerms() { return include.getTerms(); }
public void extractTerms(Set terms) { include.extractTerms(terms); }
public String toString(String field) { public String toString(String field) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Collection; import java.util.Collection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.PriorityQueue;
@ -56,6 +57,10 @@ public class SpanOrQuery extends SpanQuery {
public String getField() { return field; } 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() { public Collection getTerms() {
Collection terms = new ArrayList(); Collection terms = new ArrayList();
Iterator i = clauses.iterator(); Iterator i = clauses.iterator();
@ -65,6 +70,15 @@ public class SpanOrQuery extends SpanQuery {
} }
return terms; 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 { public Query rewrite(IndexReader reader) throws IOException {
SpanOrQuery clone = null; SpanOrQuery clone = null;

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query; 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.*/ /** Returns the name of the field matched by this query.*/
public abstract String getField(); 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(); public abstract Collection getTerms();
protected Weight createWeight(Searcher searcher) throws IOException { protected Weight createWeight(Searcher searcher) throws IOException {

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -37,12 +38,19 @@ public class SpanTermQuery extends SpanQuery {
public Term getTerm() { return term; } public Term getTerm() { return term; }
public String getField() { return term.field(); } 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() { public Collection getTerms() {
Collection terms = new ArrayList(); Collection terms = new ArrayList();
terms.add(term); terms.add(term);
return terms; return terms;
} }
public void extractTerms(Set terms) {
terms.add(term);
}
public String toString(String field) { public String toString(String field) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View File

@ -18,8 +18,9 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Collection; import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -38,14 +39,15 @@ class SpanWeight implements Weight {
private float queryNorm; private float queryNorm;
private float queryWeight; private float queryWeight;
private Collection terms; private Set terms;
private SpanQuery query; private SpanQuery query;
public SpanWeight(SpanQuery query, Searcher searcher) public SpanWeight(SpanQuery query, Searcher searcher)
throws IOException { throws IOException {
this.similarity = query.getSimilarity(searcher); this.similarity = query.getSimilarity(searcher);
this.query = query; this.query = query;
this.terms = query.getTerms(); terms=new HashSet();
query.extractTerms(terms);
idf = this.query.getSimilarity(searcher).idf(terms, searcher); idf = this.query.getSimilarity(searcher).idf(terms, searcher);
} }