You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/04/13 08:55:06 UTC

svn commit: r1673119 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/CHANGES.txt lucene/queries/ lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java

Author: jpountz
Date: Mon Apr 13 06:55:06 2015
New Revision: 1673119

URL: http://svn.apache.org/r1673119
Log:
LUCENE-6415: Make TermsQuery.extractTerms a no-op instead of throwing an UOE.

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1673119&r1=1673118&r2=1673119&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Mon Apr 13 06:55:06 2015
@@ -53,6 +53,9 @@ Bug Fixes
 * LUCENE-6378: Fix all RuntimeExceptions to throw the underlying root cause.
   (Varun Thacker, Adrien Grand, Mike McCandless)
 
+* LUCENE-6415: TermsQuery.extractTerms is a no-op (used to throw an
+  UnsupportedOperationException). (Adrien Grand)
+
 API Changes
 
 * LUCENE-6377: SearcherFactory#newSearcher now accepts the previous reader

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java?rev=1673119&r1=1673118&r2=1673119&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java Mon Apr 13 06:55:06 2015
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.lucene.index.Fields;
 import org.apache.lucene.index.LeafReader;
@@ -53,9 +54,21 @@ import org.apache.lucene.util.ToStringUt
  * Specialization for a disjunction over many terms that behaves like a
  * {@link ConstantScoreQuery} over a {@link BooleanQuery} containing only
  * {@link org.apache.lucene.search.BooleanClause.Occur#SHOULD} clauses.
- * This query creates a bit set and sets bits that matches any of the wrapped
- * terms. While this might help performance when there are many terms, it would
- * be slower than a {@link BooleanQuery} when there are few terms to match.
+ * <p>For instance in the following example, both @{code q1} and {@code q2}
+ * would yield the same scores:
+ * <pre class="prettyprint">
+ * Query q1 = new TermsQuery(new Term("field", "foo"), new Term("field", "bar"));
+ * 
+ * BooleanQuery bq = new BooleanQuery();
+ * bq.add(new TermQuery(new Term("field", "foo")), Occur.SHOULD);
+ * bq.add(new TermQuery(new Term("field", "bar")), Occur.SHOULD);
+ * Query q2 = new ConstantScoreQuery(bq);
+ * </pre>
+ * <p>This query creates a bit set and sets bits that match any of the
+ * wrapped terms. While this might help performance when there are many terms,
+ * it would be slower than a {@link BooleanQuery} when there are few terms to
+ * match.
+ * <p>NOTE: This query produces scores that are equal to its boost
  */
 public class TermsQuery extends Query implements Accountable {
 
@@ -249,6 +262,14 @@ public class TermsQuery extends Query im
     return Collections.emptyList();
   }
 
+  @Override
+  public void extractTerms(Set<Term> terms) {
+    // no-op
+    // This query is for abuse cases when the number of terms is too high to
+    // run efficiently as a BooleanQuery. So likewise we hide its terms in
+    // order to protect highlighters
+  }
+
   private static final class TermsAndField implements Accountable {
 
     private static final long BASE_RAM_BYTES_USED =