Jerry,

On Monday 24 January 2005 18:26, Jerry Jalenak wrote:
> 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)

Unless "account" is a primary key fied, it's better to loop over the termdocs.

>                               {
>                                       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...

I don't see any recursion in your code, but this output
suggests nesting three deep. Something does not add up here.

> ... Found 0 matching documents in 1000 ms
> 
> Can anyone tell me what I've done wrong?

Maybe all query hits were filtered out?
Could you compare the docnrs in the bits of the filter with the
unfiltered query hits docnrs?

Regards,
Paul Elschot


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

Reply via email to