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

Andi Vajda vajda at osafoundation.org
Tue Nov 13 11:29:40 PST 2007


On Tue, 13 Nov 2007, Bill Janssen wrote:

> I like to override QueryParser.parse() to do some post-processing of
> the query, but sadly it's not exposed by PythonMultiFieldQueryParser.
> Could you add that to the list of native methods in that class?

Look at [1] to see how it's done. With jcc, it's trivial to add other 
such methods:
   - edit [1] to have your extra methods following the pattern of the other
     native methods in there
   - make clean
   - make

Of course, there can be catches, such as returning data in an array passed in 
as argument (not directly supported) or, as is the case with QueryParser and 
MultiFieldQueryParser where the latter is a subclass of the former but the 
latter declares a static parse() clashing with the non-static parse() method 
on the former. With python, this is somewhat problematic.

In gcj-PyLucene, I had patched the Lucene source code to to rename the method 
and the wrapper was written manually. So, what are your options with 
jcc-PyLucene ?

In [1], you could add another non-static, non-native, method named, say 
parseQuery(), that calls the static parse() method and that implements your 
customization in Java. Or, you could do the same in Python directly, have your 
parseQuery() method be defined in your Python subclass of 
PythonMultiFieldQueryParser, have it call parse() and do the customization 
there.

[1] http://svn.osafoundation.org/pylucene/trunk/jcc/java/org/osafoundation/lucene/queryParser/PythonMultiFieldQueryParser.java

Andi..


More information about the pylucene-dev mailing list