lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Beard, Brian" <>
Subject RE: Post processing to get around TooManyClauses?
Date Tue, 11 Dec 2007 13:59:27 GMT
I had a similar problem (I think). Look at using a WildcardFilter
(below), possibly wrapped in a CachingWrapperFilter, depending if you
want to re-use it. I over-rode the method QueryParser.getWildcardQuery
to customize it. In your case you would probably have to specifically
detect for the presence of a wildcard to use this.

Someone posted this a while back which I found helpful.

 * This is used to construct wildcard queries
 * to avoid the 'too many boolean clauses' exception.
public class WildcardFilter extends Filter {

    private Term term;

    public WildcardFilter(Term term) {
        this.term = term;

     * A bit corrresponds to each document in the index and is set to
true if
     * it matches the criterion in the wildcard search.
     * @param reader - the indexReader @see
     * @return @see
    public BitSet bits(IndexReader reader) throws IOException {
        BitSet bits = new BitSet(reader.maxDoc());
        WildcardTermEnum enumerator = new WildcardTermEnum(reader,
        TermDocs termDocs = reader.termDocs();

        try {
            do {
                Term term = enumerator.term();

                if (term != null) {

                    while ( {
                } else {
            } while (;
        } finally {

        return bits;

-----Original Message-----
From: d33mb33 [] 
Sent: Tuesday, December 11, 2007 8:18 AM
Subject: Re: Post processing to get around TooManyClauses?

Ok I'm still struggling with this and a QueryFilter didn't help me one

I'm trying to query for books by "Charles Dickens" that start with "m".
have constructed a QueryFilter for the author search and a PrefixQuery
the title search.  A simplified version of my code is below.

    ' Charles Dickens query filter
    Dim authorQry As TermQuery = New TermQuery(New
    Dim authorFlter As QueryFilter = New QueryFilter(authorQry)

    ' M* query
    Dim titleQry As PrefixQuery = New PrefixQuery(New Term("Title",

    Dim topDocs As TopDocs = GetIndexSearcher().Search(titleQry,
authorFlter, maxResults)

This still throws a TooManyClauses exception because the PrefixQuery is
being expanded across the entire index.  
View this message in context:
Sent from the Lucene - Java Users mailing list archive at

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

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

View raw message