You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Erik Hatcher <er...@ehatchersolutions.com> on 2004/05/08 17:15:03 UTC
FilteredQuery bug
In my toying with FilteredQuery, I've found a bug. I've added a test
case (with a commented out hacked fix) to TestFilteredQuery.
A Query.rewrite is needed somewhere, although I'm not sure the best
place for it. Should FilteredQuery override rewrite? Or should it
simply rewrite the nested Query in the constructor? Or another
possibility?
FilteredQuery is cool... although my head is spinning with QueryFilter,
FilteredQuery, and Filter (as well as the completely unrelated
TokenFilter). I'm still trying to work out a compelling example of why
you'd use FilteredQuery over the other options - I'd love to see how it
is being used.
Erik
On May 8, 2004, at 11:06 AM, ehatcher@apache.org wrote:
> ehatcher 2004/05/08 08:06:19
>
> Modified: src/test/org/apache/lucene/search TestFilteredQuery.java
> Log:
> expected, then actual :) also, uncovered a bug in FilteredQuery, a
> rewrite is needed somewhere
>
> Revision Changes Path
> 1.2 +21 -9
> jakarta-lucene/src/test/org/apache/lucene/search/
> TestFilteredQuery.java
>
> Index: TestFilteredQuery.java
> ===================================================================
> RCS file:
> /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/
> TestFilteredQuery.java,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -r1.1 -r1.2
> --- TestFilteredQuery.java 21 Apr 2004 19:18:44 -0000 1.1
> +++ TestFilteredQuery.java 8 May 2004 15:06:19 -0000 1.2
> @@ -95,24 +95,36 @@
> throws Exception {
> Query filteredquery = new FilteredQuery (query, filter);
> Hits hits = searcher.search (filteredquery);
> - assertEquals (hits.length(), 1);
> - assertEquals (hits.id(0), 1);
> + assertEquals (1, hits.length());
> + assertEquals (1, hits.id(0));
>
> hits = searcher.search (filteredquery, new Sort("sorter"));
> - assertEquals (hits.length(), 1);
> - assertEquals (hits.id(0), 1);
> + assertEquals (1, hits.length());
> + assertEquals (1, hits.id(0));
>
> filteredquery = new FilteredQuery (new TermQuery (new Term
> ("field", "one")), filter);
> hits = searcher.search (filteredquery);
> - assertEquals (hits.length(), 2);
> + assertEquals (2, hits.length());
>
> filteredquery = new FilteredQuery (new TermQuery (new Term
> ("field", "x")), filter);
> hits = searcher.search (filteredquery);
> - assertEquals (hits.length(), 1);
> - assertEquals (hits.id(0), 3);
> + assertEquals (1, hits.length());
> + assertEquals (3, hits.id(0));
>
> filteredquery = new FilteredQuery (new TermQuery (new Term
> ("field", "y")), filter);
> hits = searcher.search (filteredquery);
> - assertEquals (hits.length(), 0);
> + assertEquals (0, hits.length());
> }
> +
> + public void testRangeQuery() throws Exception {
> + RangeQuery rq = new RangeQuery(
> + new Term("sorter", "b"), new Term("sorter", "d"), true);
> +
> + // rq = rq.rewrite(searcher.reader) // makes the test pass
> +
> + Query filteredquery = new FilteredQuery(rq, filter);
> + Hits hits = searcher.search(filteredquery);
> + assertEquals(2, hits.length());
> + }
> +
> }
>
>
>
>
> ---------------------------------------------------------------------
> 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
Re: FilteredQuery bug
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On May 11, 2004, at 3:48 PM, Doug Cutting wrote:
> Erik Hatcher wrote:
>> In my toying with FilteredQuery, I've found a bug. I've added a test
>> case (with a commented out hacked fix) to TestFilteredQuery.
>> A Query.rewrite is needed somewhere, although I'm not sure the best
>> place for it. Should FilteredQuery override rewrite? Or should it
>> simply rewrite the nested Query in the constructor? Or another
>> possibility?
>
> I fixed this by adding a rewrite() method to FilteredQuery.
Thanks again! I would have eventually tried my hand at implementing
this myself, but wanted to wait for the collective (or Tim's) response
before proceeding.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
Re: FilteredQuery bug
Posted by Doug Cutting <cu...@apache.org>.
Erik Hatcher wrote:
> In my toying with FilteredQuery, I've found a bug. I've added a test
> case (with a commented out hacked fix) to TestFilteredQuery.
>
> A Query.rewrite is needed somewhere, although I'm not sure the best
> place for it. Should FilteredQuery override rewrite? Or should it
> simply rewrite the nested Query in the constructor? Or another
> possibility?
I fixed this by adding a rewrite() method to FilteredQuery.
Doug
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
Re: FilteredQuery bug
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
I suppose the actual bug error message would be handy too:
java.lang.UnsupportedOperationException
at org.apache.lucene.search.Query.createWeight(Query.java:78)
at
org.apache.lucene.search.FilteredQuery.createWeight(FilteredQuery.java:
60)
at org.apache.lucene.search.Query.weight(Query.java:85)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:86)
at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:64)
at org.apache.lucene.search.Hits.<init>(Hits.java:43)
at org.apache.lucene.search.Searcher.search(Searcher.java:33)
at org.apache.lucene.search.Searcher.search(Searcher.java:27)
at
org.apache.lucene.search.TestFilteredQuery.testRangeQuery(TestFilteredQu
ery.java:126)
On May 8, 2004, at 11:15 AM, Erik Hatcher wrote:
> In my toying with FilteredQuery, I've found a bug. I've added a test
> case (with a commented out hacked fix) to TestFilteredQuery.
>
> A Query.rewrite is needed somewhere, although I'm not sure the best
> place for it. Should FilteredQuery override rewrite? Or should it
> simply rewrite the nested Query in the constructor? Or another
> possibility?
>
> FilteredQuery is cool... although my head is spinning with
> QueryFilter, FilteredQuery, and Filter (as well as the completely
> unrelated TokenFilter). I'm still trying to work out a compelling
> example of why you'd use FilteredQuery over the other options - I'd
> love to see how it is being used.
>
> Erik
>
>
> On May 8, 2004, at 11:06 AM, ehatcher@apache.org wrote:
>
>> ehatcher 2004/05/08 08:06:19
>>
>> Modified: src/test/org/apache/lucene/search
>> TestFilteredQuery.java
>> Log:
>> expected, then actual :) also, uncovered a bug in FilteredQuery, a
>> rewrite is needed somewhere
>>
>> Revision Changes Path
>> 1.2 +21 -9
>> jakarta-lucene/src/test/org/apache/lucene/search/
>> TestFilteredQuery.java
>>
>> Index: TestFilteredQuery.java
>> ===================================================================
>> RCS file:
>> /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/
>> TestFilteredQuery.java,v
>> retrieving revision 1.1
>> retrieving revision 1.2
>> diff -u -r1.1 -r1.2
>> --- TestFilteredQuery.java 21 Apr 2004 19:18:44 -0000 1.1
>> +++ TestFilteredQuery.java 8 May 2004 15:06:19 -0000 1.2
>> @@ -95,24 +95,36 @@
>> throws Exception {
>> Query filteredquery = new FilteredQuery (query, filter);
>> Hits hits = searcher.search (filteredquery);
>> - assertEquals (hits.length(), 1);
>> - assertEquals (hits.id(0), 1);
>> + assertEquals (1, hits.length());
>> + assertEquals (1, hits.id(0));
>>
>> hits = searcher.search (filteredquery, new Sort("sorter"));
>> - assertEquals (hits.length(), 1);
>> - assertEquals (hits.id(0), 1);
>> + assertEquals (1, hits.length());
>> + assertEquals (1, hits.id(0));
>>
>> filteredquery = new FilteredQuery (new TermQuery (new Term
>> ("field", "one")), filter);
>> hits = searcher.search (filteredquery);
>> - assertEquals (hits.length(), 2);
>> + assertEquals (2, hits.length());
>>
>> filteredquery = new FilteredQuery (new TermQuery (new Term
>> ("field", "x")), filter);
>> hits = searcher.search (filteredquery);
>> - assertEquals (hits.length(), 1);
>> - assertEquals (hits.id(0), 3);
>> + assertEquals (1, hits.length());
>> + assertEquals (3, hits.id(0));
>>
>> filteredquery = new FilteredQuery (new TermQuery (new Term
>> ("field", "y")), filter);
>> hits = searcher.search (filteredquery);
>> - assertEquals (hits.length(), 0);
>> + assertEquals (0, hits.length());
>> }
>> +
>> + public void testRangeQuery() throws Exception {
>> + RangeQuery rq = new RangeQuery(
>> + new Term("sorter", "b"), new Term("sorter", "d"), true);
>> +
>> + // rq = rq.rewrite(searcher.reader) // makes the test pass
>> +
>> + Query filteredquery = new FilteredQuery(rq, filter);
>> + Hits hits = searcher.search(filteredquery);
>> + assertEquals(2, hits.length());
>> + }
>> +
>> }
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org