LUCENE-1977: Remove deprecated Term field and accessors in MultiTermQuery

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@824771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-10-13 14:07:16 +00:00
parent bdef31ea5c
commit e8cf50a651
8 changed files with 46 additions and 86 deletions

View File

@ -62,6 +62,9 @@ API Changes
Make new Sort(SortField...) and Sort.setSort(SortField...) varargs-
enabled. (Uwe Schindler)
* LUCENE-1977: Remove deprecated Term field and accessors in
MultiTermQuery. (Uwe Schindler)
Bug fixes
* LUCENE-1951: When the text provided to WildcardQuery has no wildcard

View File

@ -31,20 +31,7 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.memory.MemoryIndex;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.FilteredQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.search.*;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanQuery;
@ -141,14 +128,20 @@ public class WeightedSpanTermExtractor {
mtq.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
query = mtq;
}
String field;
String field = null;
if(mtq instanceof TermRangeQuery) {
field = ((TermRangeQuery)mtq).getField();
} else {
field = mtq.getTerm().field();
} else if (mtq instanceof PrefixQuery) {
field = ((PrefixQuery) mtq).getPrefix().field();
} else if (mtq instanceof WildcardQuery) {
field = ((WildcardQuery) mtq).getTerm().field();
} else if (mtq instanceof FuzzyQuery) {
field = ((FuzzyQuery) mtq).getTerm().field();
}
if (field != null) {
IndexReader ir = getReaderForField(field);
extract(query.rewrite(ir), terms);
}
IndexReader ir = getReaderForField(field);
extract(query.rewrite(ir), terms);
} else if (query instanceof MultiPhraseQuery) {
final MultiPhraseQuery mpq = (MultiPhraseQuery) query;
final List termArrays = mpq.getTermArrays();
@ -457,11 +450,11 @@ public class WeightedSpanTermExtractor {
q.setBoost(query.getBoost());
return new TermRangeQuery(q.getField(), q.getLowerTerm(), q.getUpperTerm(), q.includesLower(), q.includesUpper());
} else if(query instanceof WildcardQuery) {
MultiTermQuery q = new WildcardQuery(query.getTerm());
MultiTermQuery q = new WildcardQuery(((WildcardQuery) query).getTerm());
q.setBoost(query.getBoost());
return q;
} else if(query instanceof PrefixQuery) {
MultiTermQuery q = new PrefixQuery(query.getTerm());
MultiTermQuery q = new PrefixQuery(((PrefixQuery) query).getPrefix());
q.setBoost(q.getBoost());
return q;
} else if(query instanceof FuzzyQuery) {

View File

@ -21,6 +21,7 @@ import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.FilteredTermEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.ToStringUtils;
import java.io.IOException;
@ -32,11 +33,14 @@ import java.io.IOException;
*/
public class RegexQuery extends MultiTermQuery implements RegexQueryCapable {
private RegexCapabilities regexImpl = new JavaUtilRegexCapabilities();
private Term term;
/** Constructs a query for terms matching <code>term</code>. */
public RegexQuery(Term term) {
super(term);
this.term = term;
}
public Term getTerm() { return term; }
/**
* Defines which {@link RegexCapabilities} implementation is used by this instance.
@ -55,10 +59,20 @@ public class RegexQuery extends MultiTermQuery implements RegexQueryCapable {
}
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
Term term = new Term(getTerm().field(), getTerm().text());
return new RegexTermEnum(reader, term, regexImpl);
}
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
if (!term.field().equals(field)) {
buffer.append(term.field());
buffer.append(":");
}
buffer.append(term.text());
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
/* generated by IntelliJ IDEA */
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -60,7 +60,6 @@ public class FuzzyQuery extends MultiTermQuery {
* or if prefixLength &lt; 0
*/
public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) throws IllegalArgumentException {
super(term); // will be removed in 3.0
this.term = term;
if (minimumSimilarity >= 1.0f)
@ -125,6 +124,7 @@ public class FuzzyQuery extends MultiTermQuery {
throw new UnsupportedOperationException("FuzzyQuery cannot change rewrite method");
}
@Override
public Query rewrite(IndexReader reader) throws IOException {
if(!termLongEnough) { // can't match
return new BooleanQuery();
@ -195,18 +195,14 @@ public class FuzzyQuery extends MultiTermQuery {
}
}
protected static class ScoreTermQueue extends PriorityQueue {
protected static class ScoreTermQueue extends PriorityQueue<ScoreTerm> {
public ScoreTermQueue(int size){
initialize(size);
}
/* (non-Javadoc)
* @see org.apache.lucene.util.PriorityQueue#lessThan(java.lang.Object, java.lang.Object)
*/
protected boolean lessThan(Object a, Object b) {
ScoreTerm termA = (ScoreTerm)a;
ScoreTerm termB = (ScoreTerm)b;
@Override
protected boolean lessThan(ScoreTerm termA, ScoreTerm termB) {
if (termA.score == termB.score)
return termA.term.compareTo(termB.term) > 0;
else
@ -215,6 +211,7 @@ public class FuzzyQuery extends MultiTermQuery {
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
@ -224,6 +221,7 @@ public class FuzzyQuery extends MultiTermQuery {
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;

View File

@ -58,8 +58,6 @@ import org.apache.lucene.queryParser.QueryParser; // for javadoc
* #CONSTANT_SCORE_AUTO_REWRITE_DEFAULT} by default.
*/
public abstract class MultiTermQuery extends Query {
/* @deprecated move to sub class */
protected Term term;
protected RewriteMethod rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
transient int numberOfTerms = 0;
@ -321,15 +319,6 @@ public abstract class MultiTermQuery extends Query {
}
};
/**
* Constructs a query for terms matching <code>term</code>.
* @deprecated check sub class for possible term access - the Term does not
* make sense for all MultiTermQuerys and will be removed.
*/
public MultiTermQuery(Term term) {
this.term = term;
}
/**
* Constructs a query matching terms that cannot be represented with a single
* Term.
@ -337,15 +326,6 @@ public abstract class MultiTermQuery extends Query {
public MultiTermQuery() {
}
/**
* Returns the pattern term.
* @deprecated check sub class for possible term access - getTerm does not
* make sense for all MultiTermQuerys and will be removed.
*/
public Term getTerm() {
return term;
}
/** Construct the enumeration to be used, expanding the pattern term. */
protected abstract FilteredTermEnum getEnum(IndexReader reader)
throws IOException;
@ -386,27 +366,6 @@ public abstract class MultiTermQuery extends Query {
return rewriteMethod.rewrite(reader, this);
}
/* Prints a user-readable version of this query.
* Implemented for back compat in case MultiTermQuery
* subclasses do no implement.
*/
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
if (term != null) {
if (!term.field().equals(field)) {
buffer.append(term.field());
buffer.append(":");
}
buffer.append(term.text());
} else {
buffer.append("termPattern:unknown");
}
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
/**
* @see #setRewriteMethod
*/

View File

@ -34,7 +34,6 @@ public class PrefixQuery extends MultiTermQuery {
/** Constructs a query for terms starting with <code>prefix</code>. */
public PrefixQuery(Term prefix) {
super(prefix); //will be removed in 3.0
this.prefix = prefix;
}
@ -46,6 +45,7 @@ public class PrefixQuery extends MultiTermQuery {
}
/** Prints a user-readable version of this query. */
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
if (!prefix.field().equals(field)) {
@ -58,7 +58,7 @@ public class PrefixQuery extends MultiTermQuery {
return buffer.toString();
}
//@Override
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
@ -66,7 +66,7 @@ public class PrefixQuery extends MultiTermQuery {
return result;
}
//@Override
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;

View File

@ -41,7 +41,6 @@ public class WildcardQuery extends MultiTermQuery {
protected Term term;
public WildcardQuery(Term term) {
super(term); //will be removed in 3.0
this.term = term;
String text = term.text();
this.termContainsWildcard = (text.indexOf('*') != -1)
@ -65,6 +64,7 @@ public class WildcardQuery extends MultiTermQuery {
return term;
}
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (termIsPrefix) {
MultiTermQuery rewritten = new PrefixQuery(term.createTerm(term.text()
@ -78,6 +78,7 @@ public class WildcardQuery extends MultiTermQuery {
}
/** Prints a user-readable version of this query. */
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
if (!term.field().equals(field)) {
@ -89,7 +90,7 @@ public class WildcardQuery extends MultiTermQuery {
return buffer.toString();
}
//@Override
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
@ -97,7 +98,7 @@ public class WildcardQuery extends MultiTermQuery {
return result;
}
//@Override
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;

View File

@ -276,14 +276,6 @@ final class JustCompileSearch {
}
static final class JustCompileMultiTermQuery extends MultiTermQuery {
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
}
}
static final class JustCompilePhraseScorer extends PhraseScorer {
JustCompilePhraseScorer(Weight weight, TermPositions[] tps, int[] offsets,