I spent some time reading the Lucene in Action book this weekend (great job,
btw), and came across the section on using custom filters.  Since the data
that I need to use to filter my hit set with comes from a database, I
thought it would be worth my effort this morning to write a custom filter
that would handle the filtering for me.  So, using the example from the book
(page 210), I've coded an AccountFilter:

public class AccountFilter extends Filter
{
        public AccountFilter()
        {}
        
        public BitSet bits(IndexReader indexReader)
                throws IOException
        {
                System.out.println("Entering AccountFilter...");
                BitSet bitSet = new BitSet(indexReader.maxDoc());

                String[] reportingAccounts = new String[] {"0011", "4kfs"};
                
                int[] docs = new int[1];
                int[] freqs = new int[1];
                
                for (int i = 0; i < reportingAccounts.length; i++)
                {
                        String reportingAccount = reportingAccounts[i];
                        if (reportingAccount != null)
                        {
                                TermDocs termDocs = indexReader.termDocs(new
Term("account", reportingAccount));
                                int count = termDocs.read(docs, freqs);
                                if (count == 1)
                                {
                                        System.out.println("Setting bit
on");
                                        bitSet.set(docs[0]);
                                }
                        }
                }
                System.out.println("Leaving AccountFilter...");
                return bitSet;
        }
}

I see where the AccountFilter is setting the cooresponding 'bits', but I end
up without any 'hits':

Entering AccountFilter...
Entering AccountFilter...
Entering AccountFilter...
Setting bit on
Setting bit on
Setting bit on
Setting bit on
Setting bit on
Leaving AccountFilter...
Leaving AccountFilter...
Leaving AccountFilter...
... Found 0 matching documents in 1000 ms

Can anyone tell me what I've done wrong?

Jerry Jalenak
Senior Programmer / Analyst, Web Publishing
LabOne, Inc.
10101 Renner Blvd.
Lenexa, KS  66219
(913) 577-1496

[EMAIL PROTECTED]


> -----Original Message-----
> From: Otis Gospodnetic [mailto:[EMAIL PROTECTED]
> Sent: Friday, January 21, 2005 8:15 AM
> To: Lucene Users List
> Subject: RE: Filtering w/ Multiple Terms
> 
> 
> This:
> http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/se
> arch/BooleanQuery.TooManyClauses.html
> ?
> 
> You can control that limit via
> http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/se
> arch/BooleanQuery.html#maxClauseCount
> 
> Otis
> 
> 
> --- Jerry Jalenak <[EMAIL PROTECTED]> wrote:
> 
> > OK.  But isn't there a limit on the number of 
> BooleanQueries that can
> > be
> > combined with AND / OR / etc?
> > 
> > 
> > 
> > Jerry Jalenak
> > Senior Programmer / Analyst, Web Publishing
> > LabOne, Inc.
> > 10101 Renner Blvd.
> > Lenexa, KS  66219
> > (913) 577-1496
> > 
> > [EMAIL PROTECTED]
> > 
> > 
> > > -----Original Message-----
> > > From: Erik Hatcher [mailto:[EMAIL PROTECTED]
> > > Sent: Thursday, January 20, 2005 5:05 PM
> > > To: Lucene Users List
> > > Subject: Re: Filtering w/ Multiple Terms
> > > 
> > > 
> > > 
> > > On Jan 20, 2005, at 5:02 PM, Jerry Jalenak wrote:
> > > 
> > > > In looking at the examples for filtering of hits, it looks 
> > > like I can 
> > > > only
> > > > specify a single term; i.e.
> > > >
> > > >         Filter f = new QueryFilter(new TermQuery(new 
> Term("acct",
> > > > "acct1")));
> > > >
> > > > I need to specify more than one term in my filter.  Short of
> > using 
> > > > something
> > > > like ChainFilter, how are others handling this?
> > > 
> > > You can make as complex of a Query as you want for 
> > > QueryFilter.  If you 
> > > want to filter on multiple terms, construct a BooleanQuery 
> > > with nested 
> > > TermQuery's, either in an AND or OR fashion.
> > > 
> > >   Erik
> > > 
> > > 
> > >
> > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > > 
> > > 
> > 
> > This transmission (and any information attached to it) may be
> > confidential and
> > is intended solely for the use of the individual or entity to which
> > it is
> > addressed. If you are not the intended recipient or the person
> > responsible for
> > delivering the transmission to the intended recipient, be advised
> > that you
> > have received this transmission in error and that any use,
> > dissemination,
> > forwarding, printing, or copying of this information is strictly
> > prohibited.
> > If you have received this transmission in error, please immediately
> > notify
> > LabOne at the following email address:
> > [EMAIL PROTECTED]
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

This transmission (and any information attached to it) may be confidential and
is intended solely for the use of the individual or entity to which it is
addressed. If you are not the intended recipient or the person responsible for
delivering the transmission to the intended recipient, be advised that you
have received this transmission in error and that any use, dissemination,
forwarding, printing, or copying of this information is strictly prohibited.
If you have received this transmission in error, please immediately notify
LabOne at the following email address: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to