lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Filter !!!
Date Tue, 07 Dec 2004 07:25:43 GMT
On Dec 7, 2004, at 12:55 AM, Chris Hostetter wrote:
>
> :  Hits hits = indexSearcher.search(searchQuery, filter)   //  here I  
> want
> : to pass multiple filter...  (DateFilter,QueryFilter)
>
> You can write a Filter that takes in multiple filters and ANDs them
> together (or ORs them, it's not clear what you want)
>
>    Hits h = s.search(q,new AndFilter(df,qf));


> (I'm planing on writting a generalized "BooleanFilter" class sometime
> in the next few weeks)

Wait.... there already is a ChainedFilter in the Lucene Sandbox.   
Here's a test case I wrote for it for Lucene in Action (the test case  
is in the sandbox also):

   public void testAND() throws Exception {
     ChainedFilter chain = new ChainedFilter(
       new Filter[] {dateFilter, bobFilter}, ChainedFilter.AND);

     Hits hits = searcher.search(query, chain);
     assertEquals("AND matches just bob", MAX / 2, hits.length());
     assertEquals("bob", hits.doc(0).get("owner"));
   }

(you'll need to see the setUp method to make sense of the asserts,  
though).

<http://cvs.apache.org/viewcvs.cgi/jakarta-lucene-sandbox/ 
contributions/miscellaneous/src/java/org/apache/lucene/misc/ 
ChainedFilter.java?view=markup>

The test cases are here:

<http://cvs.apache.org/viewcvs.cgi/jakarta-lucene-sandbox/ 
contributions/miscellaneous/src/test/org/apache/lucene/misc/ 
ChainedFilterTest.java?view=markup>

It's obviously a bit more complicated than a simple AND, though, but  
does that simple case as well.

	Erik


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


Mime
View raw message