Hi,

I was trying to use SpanRegexQuery in Lucene 3.03 to find terms that match
regular expression. The reason I use SpanRegexQuery instead of RegexQuery is

because I want to get all matches of the regular expression (if there are
multiple ones in a document), not just documents containing these matches.
However when I call the getSpans()
method, I get this exception:
Exception in thread "main" java.lang.
UnsupportedOperationException: Query should have been rewritten

This is the code I used:
 SpanRegexQuery test = new SpanRegexQuery(new Term("tags", "such/.*"));
 Spans spans = test.getSpans(reader);

I switched to Lucene 3.1 in the hope of fixing this "bug", where
SpanRegexQuery is deprecated and replaced by
RegexQuery reg = new RegexQuery(new Term("tags", "such/.*"));
SpanQuery test = new SpanMultiTermQueryWrapper<RegexQuery>(reg);
Spans spans = test.getSpans(reader);

The same exception is thrown again.

I am not sure if it is a bug? How to solve this problem ? Any idea?
The getSpans() works well for other span queries.....

Best,
Tianyu

Reply via email to