Uwe, if I look at the TestSpanMultiTermQueryWrapper.testPrefix test in 3.6, it doesn't rewrite the SMTQW, but works. What's the difference? Is that test wrong/broken?

public void testPrefix() throws Exception {
 WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
 SpanQuery swq = new SpanMultiTermQueryWrapper<WildcardQuery>(wq);
 // will only match "jumps over extremely very lazy broxn dog"
 SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
 assertEquals(1, searcher.search(sfq, 10).totalHits);
}

Or, is the issue simply a peculiarity of getSpans?

-- Jack Krupansky

-----Original Message----- From: Uwe Schindler
Sent: Tuesday, August 14, 2012 5:00 AM
To: java-user@lucene.apache.org
Subject: RE: UnsupportedOperationException: Query should have been rewritten

You have to rewrite the wrapper query.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: u...@thetaphi.de


-----Original Message-----
From: Carsten Schnober [mailto:schno...@ids-mannheim.de]
Sent: Tuesday, August 14, 2012 10:59 AM
To: java-user
Subject: UnsupportedOperationException: Query should have been rewritten

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
org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.getSpans(Span
MultiTermQueryWrapper.java:114)
================================================================
======

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!
Carsten

--
Institut für Deutsche Sprache | http://www.ids-mannheim.de
Projekt KorAP                 | http://korap.ids-mannheim.de
Tel. +49-(0)621-43740789      | schno...@ids-mannheim.de
Korpusanalyseplattform der nächsten Generation Next Generation Corpus
Analysis Platform

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to