lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Harwood <>
Subject Re: using list of items to be excluded while querying
Date Fri, 17 Oct 2008 06:32:12 GMT
Yes, use TermsFilter to add your 5000 terms by calling TermsFilter.addTerm(term) repeatedly
then put that single filter as a single "not" clause in a BooleanFilter

On 17 Oct 2008, at 04:02, "prabin meitei" <> wrote:

Hi, Thanks for the reply. I looked through the Filter class. I think i can
use the TermFilter for my requirement. But I have few doubs regarding the
use of termFilter.

Can I add any number of terms to it?? say 5000 terms? Is there any limit?
Can i use this term filter by adding to another boolean filter??


On Fri, Oct 17, 2008 at 12:53 AM, Erick Erickson <>wrote:

This sounds like a filter would work here. The basic idea of a filter
is that it's a bitmap where each bit's ordinal position
represents the a doc ID. Only documents corresponding to
"on" bits are returned.

Filters can be combined, flipped, etc. All the things you'd expect
to do with a bunch of bits. See the Filter class.

See TermEnum/TermDocs for ways to get the Lucene ID
corresponding to a particular term (i.e. one of the BooleanClauses
you were creating), which corresponds to a bit to turn on or
off in your Filter.

Also see CachingWrapperFilter and ChainedFilter as well.


On Thu, Oct 16, 2008 at 2:44 PM, prabin meitei <

Hi,     I have a large index of documents of fields "id" "name" and few
while querying i do want to exclude a list of ids i passed in.

for this what i use is
Query query = new BooleanQuery();

for (int i=0; i<list.size(); i++){

              term = new Term("id", list.get(i).toString());

              termQuery = new TermQuery(term);

              query.add(termQuery, Occur.MUST_NOT);


the problem with this is that when my list size grows larger (more than
1024) it gives tooManyBooleanCauses exception.

i tried by changing the query to

query.add(new QueryParser("id", new

this also gives the same problem when list size is big.

I do not want to increase the max clause limit ('coz of performance

Is there any simple solution to such problem?

Any suggestion will be greatly appreciated.


Send instant messages to your online friends 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message