mirror of https://github.com/apache/lucene.git
LUCENE-1975: Remove deprecated SpanQuery.getTerms() and generify Query.extractTerms(Set<Term>)
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@824527 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b9e6831f3c
commit
9b9d85d9ca
|
@ -53,6 +53,9 @@ API Changes
|
|||
* LUCENE-1971: Remove deprecated RangeQuery, RangeFilter and
|
||||
ConstantScoreRangeQuery. (Uwe Schindler)
|
||||
|
||||
* LUCENE-1975: Remove deprecated SpanQuery.getTerms() and generify
|
||||
Query.extractTerms(Set<Term>) (Michael Busch)
|
||||
|
||||
Bug fixes
|
||||
|
||||
* LUCENE-1951: When the text provided to WildcardQuery has no wildcard
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
|
||||
|
@ -449,7 +450,7 @@ public class BooleanQuery extends Query {
|
|||
}
|
||||
|
||||
// inherit javadoc
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
for (Iterator i = clauses.iterator(); i.hasNext();) {
|
||||
BooleanClause clause = (BooleanClause) i.next();
|
||||
clause.getQuery().extractTerms(terms);
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
@ -42,7 +43,7 @@ public class ConstantScoreQuery extends Query {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
// OK to not add any terms when used for MultiSearcher,
|
||||
// but may not be OK for highlighting
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
|
||||
/**
|
||||
* A query that generates the union of documents produced by its subqueries, and that scores each document with the maximum
|
||||
|
@ -213,7 +214,7 @@ public class DisjunctionMaxQuery extends Query {
|
|||
}
|
||||
|
||||
// inherit javadoc
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
for (Iterator iter = disjuncts.iterator(); iter.hasNext();) {
|
||||
((Query) iter.next()).extractTerms(terms);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -187,7 +188,7 @@ extends Query {
|
|||
}
|
||||
|
||||
// inherit javadoc
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
getQuery().extractTerms(terms);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
||||
|
@ -131,7 +132,7 @@ public class MatchAllDocsQuery extends Query {
|
|||
return new MatchAllDocsWeight(searcher);
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
}
|
||||
|
||||
public String toString(String field) {
|
||||
|
|
|
@ -113,7 +113,7 @@ public class MultiPhraseQuery extends Query {
|
|||
}
|
||||
|
||||
// inherit javadoc
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
for (Iterator iter = termArrays.iterator(); iter.hasNext();) {
|
||||
Term[] arr = (Term[])iter.next();
|
||||
for (int i=0; i<arr.length; i++) {
|
||||
|
|
|
@ -251,9 +251,9 @@ public class PhraseQuery extends Query {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.lucene.search.Query#extractTerms(java.util.Set)
|
||||
* @see org.apache.lucene.search.Query#extractTerms(Set)
|
||||
*/
|
||||
public void extractTerms(Set queryTerms) {
|
||||
public void extractTerms(Set<Term> queryTerms) {
|
||||
queryTerms.addAll(terms);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
|
||||
/** The abstract base class for queries.
|
||||
<p>Instantiable subclasses are:
|
||||
|
@ -165,7 +166,7 @@ public abstract class Query implements java.io.Serializable, Cloneable {
|
|||
*
|
||||
* @throws UnsupportedOperationException if this query is not yet rewritten
|
||||
*/
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
// needs to be implemented by query subclasses
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ public class TermQuery extends Query {
|
|||
return new TermWeight(searcher);
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
terms.add(getTerm());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.ComplexExplanation;
|
||||
import org.apache.lucene.search.Explanation;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -98,7 +99,7 @@ public class CustomScoreQuery extends Query {
|
|||
}
|
||||
|
||||
/*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
subQuery.extractTerms(terms);
|
||||
for(int i = 0; i < valSrcQueries.length; i++) {
|
||||
valSrcQueries[i].extractTerms(terms);
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search.function;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
@ -58,7 +59,7 @@ public class ValueSourceQuery extends Query {
|
|||
}
|
||||
|
||||
/*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
// no terms involved here
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.search.Searcher;
|
||||
|
@ -94,12 +95,7 @@ public class FieldMaskingSpanQuery extends SpanQuery {
|
|||
return maskedQuery.getSpans(reader);
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #extractTerms(Set)} instead. */
|
||||
public Collection getTerms() {
|
||||
return maskedQuery.getTerms();
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
maskedQuery.extractTerms(terms);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
||||
|
@ -47,12 +48,6 @@ public class SpanFirstQuery extends SpanQuery implements Cloneable {
|
|||
|
||||
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) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("spanFirst(");
|
||||
|
@ -70,7 +65,7 @@ public class SpanFirstQuery extends SpanQuery implements Cloneable {
|
|||
return spanFirstQuery;
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
match.extractTerms(terms);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Set;
|
|||
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
||||
|
@ -80,21 +81,7 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
|
|||
|
||||
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();
|
||||
while (i.hasNext()) {
|
||||
SpanQuery clause = (SpanQuery)i.next();
|
||||
terms.addAll(clause.getTerms());
|
||||
}
|
||||
return terms;
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
Iterator i = clauses.iterator();
|
||||
while (i.hasNext()) {
|
||||
SpanQuery clause = (SpanQuery)i.next();
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;
|
|||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
|
||||
|
@ -49,13 +50,7 @@ public class SpanNotQuery extends SpanQuery implements Cloneable {
|
|||
|
||||
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 void extractTerms(Set<Term> terms) { include.extractTerms(terms); }
|
||||
|
||||
public String toString(String field) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.util.PriorityQueue;
|
||||
import org.apache.lucene.util.ToStringUtils;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -58,21 +59,7 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
|
|||
|
||||
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();
|
||||
while (i.hasNext()) {
|
||||
SpanQuery clause = (SpanQuery)i.next();
|
||||
terms.addAll(clause.getTerms());
|
||||
}
|
||||
return terms;
|
||||
}
|
||||
|
||||
public void extractTerms(Set terms) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
Iterator i = clauses.iterator();
|
||||
while (i.hasNext()) {
|
||||
SpanQuery clause = (SpanQuery)i.next();
|
||||
|
|
|
@ -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,12 +35,6 @@ 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.
|
||||
* @deprecated use extractTerms instead
|
||||
* @see Query#extractTerms(Set)
|
||||
*/
|
||||
public abstract Collection getTerms();
|
||||
|
||||
public Weight createWeight(Searcher searcher) throws IOException {
|
||||
return new SpanWeight(this, searcher);
|
||||
}
|
||||
|
|
|
@ -38,16 +38,7 @@ public class SpanTermQuery extends SpanQuery {
|
|||
|
||||
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) {
|
||||
public void extractTerms(Set<Term> terms) {
|
||||
terms.add(term);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,11 +77,6 @@ final class JustCompileSearchSpans {
|
|||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
||||
/** @deprecated delete in 3.0. */
|
||||
public Collection getTerms() {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
||||
public String toString(String field) {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
|
|
@ -17,28 +17,22 @@ package org.apache.lucene.search.spans;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.search.CheckHits;
|
||||
import org.apache.lucene.search.QueryUtils;
|
||||
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.CheckHits;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.QueryUtils;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TestFieldMaskingSpanQuery extends LuceneTestCase {
|
||||
|
||||
protected static Document doc(Field[] fields) {
|
||||
|
@ -137,7 +131,9 @@ public class TestFieldMaskingSpanQuery extends LuceneTestCase {
|
|||
|
||||
QueryUtils.checkEqual(q, qr);
|
||||
|
||||
assertEquals(1, qr.getTerms().size());
|
||||
Set<Term> terms = new HashSet<Term>();
|
||||
qr.extractTerms(terms);
|
||||
assertEquals(1, terms.size());
|
||||
}
|
||||
|
||||
public void testRewrite1() throws Exception {
|
||||
|
@ -155,7 +151,9 @@ public class TestFieldMaskingSpanQuery extends LuceneTestCase {
|
|||
|
||||
QueryUtils.checkUnequal(q, qr);
|
||||
|
||||
assertEquals(2, qr.getTerms().size());
|
||||
Set<Term> terms = new HashSet<Term>();
|
||||
qr.extractTerms(terms);
|
||||
assertEquals(2, terms.size());
|
||||
}
|
||||
|
||||
public void testRewrite2() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue