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/02/21 18:32:50 UTC

svn commit: r1661412 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/queries/ lucene/queries/src/java/org/apache/lucene/queries/ lucene/queries/src/test/org/apache/lucene/queries/ lucene/queryparser/ lucene/queryparser/src/java/org/apache/lucene...

Author: jpountz
Date: Sat Feb 21 17:32:49 2015
New Revision: 1661412

URL: http://svn.apache.org/r1661412
Log:
LUCENE-6270: Replace TermsFilter with TermsQuery.

Added:
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
      - copied, changed from r1661395, lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java
      - copied unchanged from r1661395, lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java
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/TermsFilter.java
    lucene/dev/branches/branch_5x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java
    lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/albumFilteredQuery.xsl
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.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=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Sat Feb 21 17:32:49 2015
@@ -95,6 +95,9 @@ API Changes
 * LUCENE-6269: Removed BooleanFilter, use a QueryWrapperFilter(BooleanQuery)
   instead. (Adrien Grand)
 
+* LUCENE-6270: Replaced TermsFilter with TermsQuery, use a
+  QueryWrapperFilter(TermsQuery) instead. (Adrien Grand)
+
 * LUCENE-6223: Move BooleanQuery.BooleanWeight to BooleanWeight.
   (Robert Muir)
 

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java Sat Feb 21 17:32:49 2015
@@ -34,6 +34,7 @@ import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.QueryWrapperFilter;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BitDocIdSet;
@@ -47,7 +48,9 @@ import org.apache.lucene.util.RamUsageEs
  * a sequence. An example might be a collection of primary keys from a database query result or perhaps
  * a choice of "category" labels picked by the end user. As a filter, this is much faster than the
  * equivalent query (a BooleanQuery with many "should" TermQueries)
+ * @deprecated Use a {@link QueryWrapperFilter} over a {@link TermsQuery} instead
  */
+@Deprecated
 public final class TermsFilter extends Filter implements Accountable {
 
   private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(TermsFilter.class);

Copied: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (from r1661395, lucene/dev/trunk/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?p2=lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java&p1=lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java&r1=1661395&r2=1661412&rev=1661412&view=diff
==============================================================================
--- lucene/dev/trunk/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 Sat Feb 21 17:32:49 2015
@@ -416,26 +416,6 @@ public class TermsQuery extends Query im
           }
 
           @Override
-          public int nextPosition() throws IOException {
-            return -1;
-          }
-
-          @Override
-          public int startOffset() throws IOException {
-            return -1;
-          }
-
-          @Override
-          public int endOffset() throws IOException {
-            return -1;
-          }
-
-          @Override
-          public BytesRef getPayload() throws IOException {
-            return null;
-          }
-
-          @Override
           public int docID() {
             return disi.docID();
           }

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java Sat Feb 21 17:32:49 2015
@@ -68,24 +68,16 @@ public class BooleanQueryBuilder impleme
 
   static BooleanClause.Occur getOccursValue(Element clauseElem) throws ParserException {
     String occs = clauseElem.getAttribute("occurs");
-    BooleanClause.Occur occurs = BooleanClause.Occur.SHOULD;
-    if ("must".equalsIgnoreCase(occs)) {
-      occurs = BooleanClause.Occur.MUST;
-    } else {
-      if ("mustNot".equalsIgnoreCase(occs)) {
-        occurs = BooleanClause.Occur.MUST_NOT;
-      } else {
-        if (("should".equalsIgnoreCase(occs)) || ("".equals(occs))) {
-          occurs = BooleanClause.Occur.SHOULD;
-        } else {
-          if (occs != null) {
-            throw new ParserException("Invalid value for \"occurs\" attribute of clause:" + occs);
-          }
-        }
-      }
+    if (occs == null || "should".equalsIgnoreCase(occs)) {
+      return BooleanClause.Occur.SHOULD;
+    } else if ("must".equalsIgnoreCase(occs)) {
+      return BooleanClause.Occur.MUST;
+    } else if ("mustNot".equalsIgnoreCase(occs)) {
+      return BooleanClause.Occur.MUST_NOT;
+    } else if ("filter".equals(occs)) {
+      return BooleanClause.Occur.FILTER;
     }
-    return occurs;
-
+    throw new ParserException("Invalid value for \"occurs\" attribute of clause:" + occs);
   }
 
 }

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/albumFilteredQuery.xsl
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/albumFilteredQuery.xsl?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/albumFilteredQuery.xsl (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/albumFilteredQuery.xsl Sat Feb 21 17:32:49 2015
@@ -21,8 +21,6 @@
 	Other query fields are fed directly through an analyzer and so do not need to adhere to  
 	traditional Lucene query syntax. Terms within a field are ORed while different fields are ANDed
  -->	
-<FilteredQuery>
-	<Query>
 		<BooleanQuery>
 			<xsl:if test="count(artist)>0">
 			    <Clause occurs="must">
@@ -39,16 +37,11 @@
 			      <TermsQuery fieldName="releaseDate"><xsl:value-of select="releaseDate"/></TermsQuery>
 			   </Clause>
 		   </xsl:if>
+			<Clause occurs="filter">
+				<TermsQuery fieldName="genre">
+					<xsl:value-of select="genre"/>
+				</TermsQuery>
+			</Clause>
 	</BooleanQuery>
-	</Query>
-	<Filter>
-		<CachedFilter>
-			<!-- Example filter to be cached for fast, repeated use -->
-			<TermsFilter fieldName="genre">			
-				<xsl:value-of select="genre"/>
-			</TermsFilter>
-		</CachedFilter>		
-	</Filter>	
-</FilteredQuery>
 </xsl:template>
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java Sat Feb 21 17:32:49 2015
@@ -17,11 +17,12 @@ package org.apache.lucene.spatial.prefix
  * limitations under the License.
  */
 
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Shape;
+import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.lucene.queries.TermsFilter;
+import org.apache.lucene.queries.TermsQuery;
 import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.QueryWrapperFilter;
 import org.apache.lucene.spatial.prefix.tree.Cell;
 import org.apache.lucene.spatial.prefix.tree.CellIterator;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
@@ -31,12 +32,12 @@ import org.apache.lucene.spatial.query.U
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 
-import java.util.ArrayList;
-import java.util.List;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
 
 /**
  * A basic implementation of {@link PrefixTreeStrategy} using a large
- * {@link TermsFilter} of all the cells from
+ * {@link TermsQuery} of all the cells from
  * {@link SpatialPrefixTree#getTreeCellIterator(com.spatial4j.core.shape.Shape, int)}.
  * It only supports the search of indexed Point shapes.
  * <p>
@@ -92,7 +93,7 @@ public class TermQueryPrefixTreeStrategy
       byteRef.bytes = masterBytes.bytes();
     }
     //unfortunately TermsFilter will needlessly sort & dedupe
-    return new TermsFilter(getFieldName(), terms);
+    return new QueryWrapperFilter(new TermsQuery(getFieldName(), terms));
   }
 
 }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java Sat Feb 21 17:32:49 2015
@@ -27,15 +27,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import com.carrotsearch.hppc.IntObjectOpenHashMap;
-import com.carrotsearch.hppc.IntOpenHashSet;
-import com.carrotsearch.hppc.LongObjectMap;
-import com.carrotsearch.hppc.LongObjectOpenHashMap;
-import com.carrotsearch.hppc.LongOpenHashSet;
-import com.carrotsearch.hppc.cursors.IntObjectCursor;
-import com.carrotsearch.hppc.cursors.LongCursor;
-import com.carrotsearch.hppc.cursors.LongObjectCursor;
-import com.carrotsearch.hppc.cursors.ObjectCursor;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.FieldInfo;
@@ -46,11 +37,12 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.index.MultiDocValues;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.queries.TermsFilter;
+import org.apache.lucene.queries.TermsQuery;
 import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.LeafCollector;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryWrapperFilter;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Sort;
@@ -89,6 +81,16 @@ import org.apache.solr.search.SolrIndexS
 import org.apache.solr.util.plugin.PluginInfoInitialized;
 import org.apache.solr.util.plugin.SolrCoreAware;
 
+import com.carrotsearch.hppc.IntObjectOpenHashMap;
+import com.carrotsearch.hppc.IntOpenHashSet;
+import com.carrotsearch.hppc.LongObjectMap;
+import com.carrotsearch.hppc.LongObjectOpenHashMap;
+import com.carrotsearch.hppc.LongOpenHashSet;
+import com.carrotsearch.hppc.cursors.IntObjectCursor;
+import com.carrotsearch.hppc.cursors.LongCursor;
+import com.carrotsearch.hppc.cursors.LongObjectCursor;
+import com.carrotsearch.hppc.cursors.ObjectCursor;
+
 /**
  * The ExpandComponent is designed to work with the CollapsingPostFilter.
  * The CollapsingPostFilter collapses a result set on a field.
@@ -658,7 +660,7 @@ public class ExpandComponent extends Sea
       bytesRefs[++index] = term.toBytesRef();
     }
 
-    return new SolrConstantScoreQuery(new TermsFilter(fname, bytesRefs));
+    return new SolrConstantScoreQuery(new QueryWrapperFilter(new TermsQuery(fname, bytesRefs)));
   }
 
   private Query getGroupQuery(String fname,
@@ -672,7 +674,7 @@ public class ExpandComponent extends Sea
       IntObjectCursor<BytesRef> cursor = it.next();
       bytesRefs[++index] = cursor.value;
     }
-    return new SolrConstantScoreQuery(new TermsFilter(fname, bytesRefs));
+    return new SolrConstantScoreQuery(new QueryWrapperFilter(new TermsQuery(fname, bytesRefs)));
   }
 
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java?rev=1661412&r1=1661411&r2=1661412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java Sat Feb 21 17:32:49 2015
@@ -17,8 +17,11 @@ package org.apache.solr.search;
  * limitations under the License.
  */
 
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queries.TermsFilter;
+import org.apache.lucene.queries.TermsQuery;
 import org.apache.lucene.search.AutomatonQuery;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
@@ -37,9 +40,6 @@ import org.apache.solr.common.util.Named
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.schema.FieldType;
 
-import java.util.Arrays;
-import java.util.regex.Pattern;
-
 /**
  * Finds documents whose specified field has any of the specified values. It's like
  * {@link TermQParserPlugin} but multi-valued, and supports a variety of internal algorithms.
@@ -68,7 +68,7 @@ public class TermsQParserPlugin extends
     termsFilter {
       @Override
       Filter makeFilter(String fname, BytesRef[] bytesRefs) {
-        return new TermsFilter(fname, bytesRefs);
+        return new QueryWrapperFilter(new TermsQuery(fname, bytesRefs));
       }
     },
     booleanQuery {