lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r791176 - in /lucene/java/trunk/src/java/org/apache/lucene/search: RangeFilter.java RangeQuery.java
Date Sat, 04 Jul 2009 20:15:20 GMT
Author: uschindler
Date: Sat Jul  4 20:15:20 2009
New Revision: 791176

URL: http://svn.apache.org/viewvc?rev=791176&view=rev
Log:
LUCENE-1713: Rename RangeQuery -> TermRangeQuery (part 2)

Added:
    lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java   (with props)
    lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java   (with props)

Added: lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java?rev=791176&view=auto
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java (added)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java Sat Jul  4 20:15:20
2009
@@ -0,0 +1,92 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.Collator;
+
+/**
+ * A Filter that restricts search results to a range of values in a given
+ * field.
+ *
+ * <p>This filter matches the documents looking for terms that fall into the
+ * supplied range according to {@link String#compareTo(String)}. It is not intended
+ * for numerical ranges, use {@link NumericRangeFilter} instead.
+ *
+ * <p>If you construct a large number of range filters with different ranges but on
the 
+ * same field, {@link FieldCacheRangeFilter} may have significantly better performance. 
+ *
+ * @deprecated Use {@link TermRangeFilter} for term ranges or
+ * {@link NumericRangeFilter} for numeric ranges instead.
+ * This class will be removed in Lucene 3.0.
+ */
+public class RangeFilter extends MultiTermQueryWrapperFilter {
+    
+  /**
+   * @param fieldName The field this range applies to
+   * @param lowerTerm The lower bound on this range
+   * @param upperTerm The upper bound on this range
+   * @param includeLower Does this range include the lower bound?
+   * @param includeUpper Does this range include the upper bound?
+   * @throws IllegalArgumentException if both terms are null or if
+   *  lowerTerm is null and includeLower is true (similar for upperTerm
+   *  and includeUpper)
+   */
+  public RangeFilter(String fieldName, String lowerTerm, String upperTerm,
+                     boolean includeLower, boolean includeUpper) {
+      super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
+  }
+
+  /**
+   * <strong>WARNING:</strong> Using this constructor and supplying a non-null
+   * value in the <code>collator</code> parameter will cause every single 
+   * index Term in the Field referenced by lowerTerm and/or upperTerm to be
+   * examined.  Depending on the number of index Terms in this Field, the 
+   * operation could be very slow.
+   *
+   * @param lowerTerm The lower bound on this range
+   * @param upperTerm The upper bound on this range
+   * @param includeLower Does this range include the lower bound?
+   * @param includeUpper Does this range include the upper bound?
+   * @param collator The collator to use when determining range inclusion; set
+   *  to null to use Unicode code point ordering instead of collation.
+   * @throws IllegalArgumentException if both terms are null or if
+   *  lowerTerm is null and includeLower is true (similar for upperTerm
+   *  and includeUpper)
+   */
+  public RangeFilter(String fieldName, String lowerTerm, String upperTerm,
+                     boolean includeLower, boolean includeUpper,
+                     Collator collator) {
+      super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper,
collator));
+  }
+
+  /**
+   * Constructs a filter for field <code>fieldName</code> matching
+   * less than or equal to <code>upperTerm</code>.
+   */
+  public static RangeFilter Less(String fieldName, String upperTerm) {
+      return new RangeFilter(fieldName, null, upperTerm, false, true);
+  }
+
+  /**
+   * Constructs a filter for field <code>fieldName</code> matching
+   * greater than or equal to <code>lowerTerm</code>.
+   */
+  public static RangeFilter More(String fieldName, String lowerTerm) {
+      return new RangeFilter(fieldName, lowerTerm, null, true, false);
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java?rev=791176&view=auto
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java (added)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java Sat Jul  4 20:15:20
2009
@@ -0,0 +1,152 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.Collator;
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+
+/**
+ * A Query that matches documents within an exclusive range of terms.
+ *
+ * <p>This query matches the documents looking for terms that fall into the
+ * supplied range according to {@link String#compareTo(String)}. It is not intended
+ * for numerical ranges, use {@link NumericRangeQuery} instead.
+ *
+ * <p>See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between
+ * enabling and disabling constantScoreRewrite mode.
+ *
+ * @deprecated Use {@link TermRangeQuery} for term ranges or
+ * {@link NumericRangeQuery} for numeric ranges instead.
+ * This class will be removed in Lucene 3.0.
+ */
+public class RangeQuery extends Query {
+  private final TermRangeQuery delegate;
+
+  /** Constructs a query selecting all terms greater than
+   * <code>lowerTerm</code> but less than <code>upperTerm</code>.
+   * There must be at least one term and either term may be null,
+   * in which case there is no bound on that side, but if there are
+   * two terms, both terms <b>must</b> be for the same field.
+   *
+   * @param lowerTerm The Term at the lower end of the range
+   * @param upperTerm The Term at the upper end of the range
+   * @param inclusive If true, both <code>lowerTerm</code> and
+   *  <code>upperTerm</code> will themselves be included in the range.
+   */
+  public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) {
+    this(lowerTerm, upperTerm, inclusive, null);
+  }
+
+  /** Constructs a query selecting all terms greater than
+   * <code>lowerTerm</code> but less than <code>upperTerm</code>.
+   * There must be at least one term and either term may be null,
+   * in which case there is no bound on that side, but if there are
+   * two terms, both terms <b>must</b> be for the same field.
+   * <p>
+   * If <code>collator</code> is not null, it will be used to decide whether
+   * index terms are within the given range, rather than using the Unicode code
+   * point order in which index terms are stored.
+   * <p>
+   * <strong>WARNING:</strong> Using this constructor and supplying a non-null
+   * value in the <code>collator</code> parameter will cause every single 
+   * index Term in the Field referenced by lowerTerm and/or upperTerm to be
+   * examined.  Depending on the number of index Terms in this Field, the 
+   * operation could be very slow.
+   *
+   * @param lowerTerm The Term at the lower end of the range
+   * @param upperTerm The Term at the upper end of the range
+   * @param inclusive If true, both <code>lowerTerm</code> and
+   *  <code>upperTerm</code> will themselves be included in the range.
+   * @param collator The collator to use to collate index Terms, to determine
+   *  their membership in the range bounded by <code>lowerTerm</code> and
+   *  <code>upperTerm</code>.
+   */
+  public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, Collator collator)
{
+    if (lowerTerm == null && upperTerm == null)
+      throw new IllegalArgumentException("At least one term must be non-null");
+    if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field())
+      throw new IllegalArgumentException("Both terms must have the same field");
+      
+    delegate = new TermRangeQuery(
+      (lowerTerm == null) ? upperTerm.field() : lowerTerm.field(), 
+      (lowerTerm == null) ? null : lowerTerm.text(), 
+      (upperTerm == null) ? null : upperTerm.text(), 
+      inclusive, inclusive,
+      collator
+    );
+    delegate.setConstantScoreRewrite(false);
+  }
+  
+  public void setBoost(float b) {
+    super.setBoost(b);
+    delegate.setBoost(b);
+  }
+
+  public Query rewrite(IndexReader reader) throws IOException {
+    return delegate.rewrite(reader);
+  }
+
+  /** Returns the field name for this query */
+  public String getField() {
+    return delegate.getField();
+  }
+
+  /** Returns the lower term of this range query. */
+  public Term getLowerTerm() {
+    final String term = delegate.getLowerTerm();
+    return (term == null) ? null : new Term(getField(), term);
+  }
+
+  /** Returns the upper term of this range query. */
+  public Term getUpperTerm() {
+    final String term = delegate.getUpperTerm();
+    return (term == null) ? null : new Term(getField(), term);
+  }
+
+  /** Returns <code>true</code> if the range query is inclusive */
+  public boolean isInclusive() {
+    return delegate.includesLower() && delegate.includesUpper();
+  }
+
+  /** Returns the collator used to determine range inclusion, if any. */
+  public Collator getCollator() {
+    return delegate.getCollator();
+  }
+
+  /** Prints a user-readable version of this query. */
+  public String toString(String field) {
+    return delegate.toString(field);
+  }
+
+  /** Returns true iff <code>o</code> is equal to this. */
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof RangeQuery)) return false;
+
+    final RangeQuery other = (RangeQuery) o;
+    return this.delegate.equals(other.delegate);
+  }
+
+  /** Returns a hash code value for this object.*/
+  public int hashCode() {
+    return delegate.hashCode();
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message