Mailing List Archive

cleaned up legacy code in BooleanQuery
The mask logic in the BooleanQuery.scorer is no longer needed because it
has moved to the BooleanScorer.add.
Besides, the 32-clause limitation may need to go in the future and it
would be simpler to fix it in one place.
Here's the diff:

Index: java/org/apache/lucene/search/BooleanQuery.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java,v
retrieving revision 1.1.1.1
diff -B -r1.1.1.1 BooleanQuery.java
130d129
< int theMask = 1, thisMask;
132,143c131,136
< BooleanClause c = (BooleanClause)clauses.elementAt(i);
< if (c.required || c.prohibited) {
< thisMask = theMask;
< theMask = theMask << 1;
< } else
< thisMask = 0;
<
< Scorer subScorer = c.query.scorer(reader);
< if (subScorer != null)
< result.add(subScorer, c.required, c.prohibited);
< else if (c.required)
< return null;
---
> BooleanClause c = (BooleanClause)clauses.elementAt(i);
> Scorer subScorer = c.query.scorer(reader);
> if (subScorer != null)
> result.add(subScorer, c.required, c.prohibited);
> else if (c.required)
> return null;
145,147d137
< if (theMask == 0)
< throw new IndexOutOfBoundsException
< ("More than 32 required/prohibited clauses in query.");
RE: cleaned up legacy code in BooleanQuery [ In reply to ]
> Besides, the 32-clause limitation may need to go in the future and it
> would be simpler to fix it in one place.

What is the reason for the 32-clause limitation?

Thanks,
Scott
Re: cleaned up legacy code in BooleanQuery [ In reply to ]
From what I can tell, it is because BooleanScorer uses an integer
bitmask to keep track of how a particular document satisfies the
criteria of each clause of the query. Each clause gets a bit. This only
applies to the required and prohibited clauses, so the MultiTermQuery
(and friends) are not effected by this because they use "optional"
clauses (not required and not prohibited).

I think it would be possible to use a BitVector instead, but I'm not
sure what performance implications that would have. Besides, it seems
that even if more than 32 clauses were required, one could always create
two boolean queries and join them with a third one, so I'm not sure how
important it is to remove this limit.

Scott Ganyo wrote:

>>Besides, the 32-clause limitation may need to go in the future and it
>>would be simpler to fix it in one place.
>>
>
>What is the reason for the 32-clause limitation?
>
>Thanks,
>Scott
>
RE: cleaned up legacy code in BooleanQuery [ In reply to ]
Looks like a good cleanup to me.

Doug

> -----Original Message-----
> From: Dmitry Serebrennikov [mailto:dmitrys@earthlink.net]
> Sent: Sunday, October 07, 2001 5:10 PM
> To: lucene-dev@jakarta.apache.org
> Subject: cleaned up legacy code in BooleanQuery
>
>
> The mask logic in the BooleanQuery.scorer is no longer needed
> because it
> has moved to the BooleanScorer.add.
> Besides, the 32-clause limitation may need to go in the future and it
> would be simpler to fix it in one place.
> Here's the diff:
>
> Index: java/org/apache/lucene/search/BooleanQuery.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/sear
> ch/BooleanQuery.java,v
> retrieving revision 1.1.1.1
> diff -B -r1.1.1.1 BooleanQuery.java
> 130d129
> < int theMask = 1, thisMask;
> 132,143c131,136
> < BooleanClause c = (BooleanClause)clauses.elementAt(i);
> < if (c.required || c.prohibited) {
> < thisMask = theMask;
> < theMask = theMask << 1;
> < } else
> < thisMask = 0;
> <
> < Scorer subScorer = c.query.scorer(reader);
> < if (subScorer != null)
> < result.add(subScorer, c.required, c.prohibited);
> < else if (c.required)
> < return null;
> ---
> > BooleanClause c = (BooleanClause)clauses.elementAt(i);
> > Scorer subScorer = c.query.scorer(reader);
> > if (subScorer != null)
> > result.add(subScorer, c.required, c.prohibited);
> > else if (c.required)
> > return null;
> 145,147d137
> < if (theMask == 0)
> < throw new IndexOutOfBoundsException
> < ("More than 32 required/prohibited clauses in query.");
>
>