[pylucene-dev] can't override QueryParser.parse()

Andi Vajda vajda at osafoundation.org
Wed Nov 14 11:02:06 PST 2007

On Wed, 14 Nov 2007, Andi Vajda wrote:

> On Wed, 14 Nov 2007, Bill Janssen wrote:
>>>> But I still have the problem reflected in the stack trace with GDB:
>>>> the "value" being extracted is not of the Python type JavaError (it's
>>>> of the Python type "Throwable"), and doesn't have the method
>>>> "getJavaException", while the "exc" *is* of type JavaError.  Either
>>>> the code in PyErr_SetJavaError() isn't correct, or the code in
>>>> throwPythonError() isn't correct.
>>> Quite possibly so. If your contention is correct, then change line 565 in
>>> functions.cpp to call 'getJavaException' on 'exc' instead  of 'value'.
>> Actually, I misspoke.  "exc" is of type "type" -- it's the "JavaError"
>> type object.  I think the right fix is to not call "getJavaException"
>> at all; you've got the Throwable right there in your hand already.
> Yes, that's what I'm currently thinking too. 'value' _is_ the throwable.
> The code in functions.cpp could be significantly simpler, in that case.

I changed your sample code to raise a JavaError with a Java RuntimeException 
as argument in getBooleanQuery() and stepping through throwPythonError() 
shows that the code there is correct. 'value' is the JavaError exception 
instance and calling 'getJavaException()' on it returns the 

If there is a bug, it's elsewhere.


from lucene import initVM, CLASSPATH, JavaError, RuntimeException
from lucene import \
     QueryParser, StandardAnalyzer, PythonMultiFieldQueryParser


class MyQueryParser(PythonMultiFieldQueryParser):
     def getBooleanQuery(self, *args):
         raise JavaError, RuntimeException("foo")

p = MyQueryParser(['bletch', 'unbletch'], StandardAnalyzer())
print QueryParser.parse(p, "foo AND bar")

More information about the pylucene-dev mailing list