lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carsten Schnober <>
Subject UnsupportedOperationException: Query should have been rewritten
Date Tue, 14 Aug 2012 08:58:46 GMT
Dear list,
I am trying to combine a WildcardQuery and a SpanQuery because I need to
extract spans from the index for further processing. I realise that
there have been a few public discussions about this topic around, but I
still fail to get what I am missing here. My code is this (Lucene 3.6.0):

WildcardQuery wildcard = new WildcardQuery(new Term("field", "bro*"));
SpanQuery query = new SpanMultiTermQueryWrapper<WildcardQuery>(wildcard);		
// query = query.rewrite(reader);		
Spans luceneSpans = query.getSpans(reader);

This throws the following exception:
Exception in thread "main" java.lang.UnsupportedOperationException:
Query should have been rewritten at

I am basically aware of the problem that I cannot apply a MultiTermQuery
instance (like a WildcardQuery) without calling rewrite(), but on the
other hand, rewrite() returns a Query object that I cannot use as a
SpanQuery instance.

I'm almost sure that there is a reasonable solution for this problem
that I am not able to spot. Or do I have to migrate either to Lucene 4
or use a SpanRegexQuery instead which I do not really want to because it
is marked as deprecated.

Thank you very much!

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