lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r824771 - in /lucene/java/trunk: ./ contrib/highlighter/src/java/org/apache/lucene/search/highlight/ contrib/regex/src/java/org/apache/lucene/search/regex/ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/search/
Date Tue, 13 Oct 2009 14:07:17 GMT
Author: uschindler
Date: Tue Oct 13 14:07:16 2009
New Revision: 824771

URL: http://svn.apache.org/viewvc?rev=824771&view=rev
Log:
LUCENE-1977: Remove deprecated Term field and accessors in MultiTermQuery

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
    lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Oct 13 14:07:16 2009
@@ -62,6 +62,9 @@
   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

Modified: lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
(original)
+++ lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
Tue Oct 13 14:07:16 2009
@@ -31,20 +31,7 @@
 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 @@
         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 @@
       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) {

Modified: lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
(original)
+++ lucene/java/trunk/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
Tue Oct 13 14:07:16 2009
@@ -21,6 +21,7 @@
 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 @@
  */
 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 @@
   }
 
   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;

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java Tue Oct 13 14:07:16
2009
@@ -60,7 +60,6 @@
    * 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 @@
     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 @@
     }
   }
   
-  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 @@
     
   }
 
+  @Override
   public int hashCode() {
     final int prime = 31;
     int result = super.hashCode();
@@ -224,6 +221,7 @@
     return result;
   }
 
+  @Override
   public boolean equals(Object obj) {
     if (this == obj)
       return true;

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java Tue Oct 13 14:07:16
2009
@@ -58,8 +58,6 @@
  * #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;
 
@@ -322,30 +320,12 @@
   };
 
   /**
-   * 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.
    */
   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 @@
     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
    */

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/PrefixQuery.java Tue Oct 13 14:07:16
2009
@@ -34,7 +34,6 @@
 
   /** 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 @@
   }
 
   /** 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 @@
     return buffer.toString();
   }
 
-  //@Override
+  @Override
   public int hashCode() {
     final int prime = 31;
     int result = super.hashCode();
@@ -66,7 +66,7 @@
     return result;
   }
 
-  //@Override
+  @Override
   public boolean equals(Object obj) {
     if (this == obj)
       return true;

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/WildcardQuery.java Tue Oct 13 14:07:16
2009
@@ -41,7 +41,6 @@
   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 @@
     return term;
   }
 
+  @Override
   public Query rewrite(IndexReader reader) throws IOException {
     if (termIsPrefix) {
       MultiTermQuery rewritten = new PrefixQuery(term.createTerm(term.text()
@@ -78,6 +78,7 @@
   }
   
   /** 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 @@
     return buffer.toString();
   }
 
-  //@Override
+  @Override
   public int hashCode() {
     final int prime = 31;
     int result = super.hashCode();
@@ -97,7 +98,7 @@
     return result;
   }
 
-  //@Override
+  @Override
   public boolean equals(Object obj) {
     if (this == obj)
       return true;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=824771&r1=824770&r2=824771&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java Tue Oct 13
14:07:16 2009
@@ -276,14 +276,6 @@
     
   }
 
-  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,



Mime
View raw message