List Info

Thread: RE: Wildcard & filters




RE: Wildcard & filters
country flaguser name
United States
2007-10-12 12:58:55
Mark,

Thanks so much.

-----Original Message-----
From: Mark Miller [mailto:markrmillergmail.com] 
Sent: Friday, October 12, 2007 1:54 PM
To: java-userlucene.apache.org
Subject: Re: Wildcard & filters

Something along these lines:

public class WildcardFilter extends Filter {
    private Term term;

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

    Override
    public BitSet bits(IndexReader reader) throws
IOException {
        BitSet bits = new BitSet();
        WildcardTermEnum enumerator = new
WildcardTermEnum(reader,
term);
        TermDocs termDocs = reader.termDocs();

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

                if (term != null) {
                    termDocs.seek(term);

                    while (termDocs.next()) {
                        bits.set(termDocs.doc());
                    }
                } else {
                    break;
                }
            } while (enumerator.next());
        } finally {
            termDocs.close();
            enumerator.close();
        }

        return bits;
    }
}

- Mark

Beard, Brian wrote:
> I'm trying to over-ride QueryParser.getWildcardQuery to
use filtering.
>
> I'm missing something, because the following still gets
the
> maxBooleanClauses limit.
>
> I guess the terms are still expanded even though the
query is wrapped
in
> a filter. How do I avoid the term expansion altogether?
Is there a
> built-in way to do this?
>
> protected Query getWildcardQuery(String field, String
termStr)
> 	throws ParseException {
> 		
> 	Query wildcardQuery = new WildcardQuery(new
Term(field,
> termStr));
>
> 	QueryWrapperFilter queryWrapperFilter = new
> QueryWrapperFilter(wildcardQuery);
>
> 	ConstantScoreQuery constantScoreQuery = new
> ConstantScoreQuery(queryWrapperFilter);
>
> 	return constantScoreQuery;
>
> }
>
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
> For additional commands, e-mail: java-user-helplucene.apache.org
>
>
>   

------------------------------------------------------------
---------
To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org




------------------------------------------------------------
---------
To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org


Re: Wildcard & filters
country flaguser name
United States
2007-10-12 13:05:36
No prob....was a bit hasty though:

replace

= new BitSet();

with

= new BitSet(reader.maxDocs());


Beard, Brian wrote:
> Mark,
>
> Thanks so much.
>
> -----Original Message-----
> From: Mark Miller [mailto:markrmillergmail.com] 
> Sent: Friday, October 12, 2007 1:54 PM
> To: java-userlucene.apache.org
> Subject: Re: Wildcard & filters
>
> Something along these lines:
>
> public class WildcardFilter extends Filter {
>     private Term term;
>
>     public WildcardFilter(Term term) {
>         this.term = term;
>     }
>
>     Override
>     public BitSet bits(IndexReader reader) throws
IOException {
>         BitSet bits = new BitSet();
>         WildcardTermEnum enumerator = new
WildcardTermEnum(reader,
> term);
>         TermDocs termDocs = reader.termDocs();
>
>         try {
>             do {
>                 Term term = enumerator.term();
>
>                 if (term != null) {
>                     termDocs.seek(term);
>
>                     while (termDocs.next()) {
>                         bits.set(termDocs.doc());
>                     }
>                 } else {
>                     break;
>                 }
>             } while (enumerator.next());
>         } finally {
>             termDocs.close();
>             enumerator.close();
>         }
>
>         return bits;
>     }
> }
>
> - Mark
>
> Beard, Brian wrote:
>   
>> I'm trying to over-ride
QueryParser.getWildcardQuery to use filtering.
>>
>> I'm missing something, because the following still
gets the
>> maxBooleanClauses limit.
>>
>> I guess the terms are still expanded even though
the query is wrapped
>>     
> in
>   
>> a filter. How do I avoid the term expansion
altogether? Is there a
>> built-in way to do this?
>>
>> protected Query getWildcardQuery(String field,
String termStr)
>> 	throws ParseException {
>> 		
>> 	Query wildcardQuery = new WildcardQuery(new
Term(field,
>> termStr));
>>
>> 	QueryWrapperFilter queryWrapperFilter = new
>> QueryWrapperFilter(wildcardQuery);
>>
>> 	ConstantScoreQuery constantScoreQuery = new
>> ConstantScoreQuery(queryWrapperFilter);
>>
>> 	return constantScoreQuery;
>>
>> }
>>
>>
>>
------------------------------------------------------------
---------
>> To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
>> For additional commands, e-mail: java-user-helplucene.apache.org
>>
>>
>>   
>>     
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
> For additional commands, e-mail: java-user-helplucene.apache.org
>
>
>
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
> For additional commands, e-mail: java-user-helplucene.apache.org
>
>
>   

------------------------------------------------------------
---------
To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )