On Thu, 2 Mar 2006, Bill Janssen wrote:

I've been looking at a conversion of a Java Lucene project to
PyLucene, using PyLucene 1.9 on Python 2.3.5 on a Mac.  So far, so
good, but I don't see how to subclass MultiFieldQueryParser properly.
I have to override both "parseQuery" and "getFieldQuery" (and probably
"getRangeQuery") in my subclass.

If I use the analyzer.queryParser() trick illustrated in the examples,
"getFieldQuery" gets called, but not "parseQuery".  What's worse,
there's only one default field name with that approach, so it won't
really work.

I added another method to Analyzer wrappers, called multiFieldQueryParser(), which, like the trick you're referring to - the AdvanceQueryParserTest LuceneInAction sample - takes an instance implementing all or some of the extension points for MultiFieldQueryParser (the same as for QueryParser, see the CustomQueryParser sample class) and an array of field name strings (see line 3977 in PyLucene.i on trunk). This new method returns an instance of an extension to MultiFieldQueryParser called PythonMultiFieldQueryParser whose sole job is to call the extension points defined on your python class.

Making parseQuery overridable is trickier because that method is an entrypoint to both QueryParser and MultiFieldQueryParser and is called directly from python whereas the extension hooks (declared protected in java) such as getBooleanQuery() are not called directly from python except via the 'super' object passed to the python extension. It might be feasible to override parseQuery but would require some naming trickery that I'd rather avoid if you can get the same effect somehow otherwise.
What does your parseQuery() override actually do ?

I added a new test case to AdvanceQueryParserTest.py that uses the same CustomQueryParser python class as an extension for a MultiFieldQueryParser.

Let me know how this works for you, I checked all of this into the PyLucene trunk.

Thanks !

Andi..
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to