You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Jon Pipitone <jp...@mshri.on.ca> on 2004/02/25 20:06:02 UTC

Exposing getters on PhraseQuery and RangeQuery

Hey all,

In the process of trying to put together a simple query rewriting 
facility I came across the need to access a PrefixQuery's prefix term, 
as well as a RangeQuery's field name, lower and upper terms, and 
inclusivity status.  Unfortunately the appropriate get methods are not 
available.

Currently I've patched my local copy of Lucene; is there any reason not 
to expose these sorts of methods?  Bug 21921 [1] suggests something 
similar with the PrefixQuery but no work has been done on the bug -- so 
I might be overlooking something.

Anyhow, the following patch shows the sort of changes I'd be interested 
in seeing.

jp

[1] http://issues.apache.org/bugzilla/show_bug.cgi?id=21921


Index: src/java/org/apache/lucene/search/PrefixQuery.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/PrefixQuery.java,v
retrieving revision 1.7
diff -u -r1.7 PrefixQuery.java
--- src/java/org/apache/lucene/search/PrefixQuery.java	12 Aug 2003 
09:17:53 -0000	1.7
+++ src/java/org/apache/lucene/search/PrefixQuery.java	25 Feb 2004 
17:52:00 -0000
@@ -113,4 +113,8 @@
      }
      return buffer.toString();
    }
+
+  /** Returns the prefix of this query. */
+  public Term getPrefix() { return prefix; }
+
  }
Index: src/java/org/apache/lucene/search/RangeQuery.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/RangeQuery.java,v
retrieving revision 1.10
diff -u -r1.10 RangeQuery.java
--- src/java/org/apache/lucene/search/RangeQuery.java	10 Sep 2003 
12:24:05 -0000	1.10
+++ src/java/org/apache/lucene/search/RangeQuery.java	25 Feb 2004 
17:52:01 -0000
@@ -153,7 +153,8 @@
        return Query.mergeBooleanQueries(queries);
      }

-    private String getField()
+    /** Returns the field name for this query */
+    public String getField()
      {
          return (lowerTerm != null ? lowerTerm.field() : 
upperTerm.field());
      }
@@ -179,4 +180,13 @@
          }
          return buffer.toString();
      }
+
+    /** Returns the lower term of this range query */
+    public Term getLowerTerm() { return lowerTerm; }
+
+    /** Returns the upper term of this range query */
+    public Term getUpperTerm() { return upperTerm; }
+
+    /** Returns <code>true</code> if the range query is inclusive */
+    public boolean isInclusive() { return inclusive; }
  }


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Re: Exposing getters on PhraseQuery and RangeQuery

Posted by Doug Cutting <cu...@apache.org>.
Okay, I applied these changes.

Jon Pipitone wrote:
> Hey all,
> 
> In the process of trying to put together a simple query rewriting 
> facility I came across the need to access a PrefixQuery's prefix term, 
> as well as a RangeQuery's field name, lower and upper terms, and 
> inclusivity status.  Unfortunately the appropriate get methods are not 
> available.
> 
> Currently I've patched my local copy of Lucene; is there any reason not 
> to expose these sorts of methods?  Bug 21921 [1] suggests something 
> similar with the PrefixQuery but no work has been done on the bug -- so 
> I might be overlooking something.
> 
> Anyhow, the following patch shows the sort of changes I'd be interested 
> in seeing.
> 
> jp
> 
> [1] http://issues.apache.org/bugzilla/show_bug.cgi?id=21921
> 
> 
> Index: src/java/org/apache/lucene/search/PrefixQuery.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/PrefixQuery.java,v 
> 
> retrieving revision 1.7
> diff -u -r1.7 PrefixQuery.java
> --- src/java/org/apache/lucene/search/PrefixQuery.java    12 Aug 2003 
> 09:17:53 -0000    1.7
> +++ src/java/org/apache/lucene/search/PrefixQuery.java    25 Feb 2004 
> 17:52:00 -0000
> @@ -113,4 +113,8 @@
>      }
>      return buffer.toString();
>    }
> +
> +  /** Returns the prefix of this query. */
> +  public Term getPrefix() { return prefix; }
> +
>  }
> Index: src/java/org/apache/lucene/search/RangeQuery.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/RangeQuery.java,v 
> 
> retrieving revision 1.10
> diff -u -r1.10 RangeQuery.java
> --- src/java/org/apache/lucene/search/RangeQuery.java    10 Sep 2003 
> 12:24:05 -0000    1.10
> +++ src/java/org/apache/lucene/search/RangeQuery.java    25 Feb 2004 
> 17:52:01 -0000
> @@ -153,7 +153,8 @@
>        return Query.mergeBooleanQueries(queries);
>      }
> 
> -    private String getField()
> +    /** Returns the field name for this query */
> +    public String getField()
>      {
>          return (lowerTerm != null ? lowerTerm.field() : 
> upperTerm.field());
>      }
> @@ -179,4 +180,13 @@
>          }
>          return buffer.toString();
>      }
> +
> +    /** Returns the lower term of this range query */
> +    public Term getLowerTerm() { return lowerTerm; }
> +
> +    /** Returns the upper term of this range query */
> +    public Term getUpperTerm() { return upperTerm; }
> +
> +    /** Returns <code>true</code> if the range query is inclusive */
> +    public boolean isInclusive() { return inclusive; }
>  }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org