lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carsten Schnober <>
Subject Re: Rewrite for RegexpQuery
Date Mon, 11 Mar 2013 12:28:34 GMT
Am 11.03.2013 12:08, schrieb Uwe Schindler:

> This works for this query, but in general you have to rewrite until it is completely
rewritten: A while loop that exits when the result of the rewrite is identical to the original
query. IndexSearcher.rewrite() does this for you. 
>> 3. Write the terms into a previously initialized empty set terms:
>> Set<Term> terms = new HashSet<>();
>> q.extractTerms(terms);
> Set the rewrite method to e.g. SCORING_BOOLEAN_QUERY_REWRITE, then this should work (after
rewrite your query is a BooleanQuery, which supports extractTerms()).

This does work for my case, thank you! For the matter of completeness,
the full solution (for my specific case) is as follows:

Set<Term> terms = new HashSet<>();
MultiTermQuery query = new RegexpQuery(new Term("text", query));
BooleanQuery bq = (BooleanQuery) query.rewrite(reader);

Regarding the application of IndexSearcher.rewrite(Query) instead: I
don't see a way to set the rewrite method there because the Query's
rewrite method does not seem to apply to IndexSearcher.rewrite().


Institut für Deutsche Sprache |
Projekt KorAP                 |
Tel. +49-(0)621-43740789      |
Korpusanalyseplattform der nächsten Generation
Next Generation Corpus Analysis Platform

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

View raw message