It looks to me as if the shipped PythonQueryParser (for overriding query parsing with Python code) only overrides the getBooleanQuery(Vector), but that just calls getBooleanQuery(List,boolean), which is the function which actually does the work (in the current version of Lucene).
I've attached a patch and a test case for PythonQueryParser. It looks like a very similar patch is needed for PythonMultiFieldQueryParser, but the attached test case generates a java null pointer reference exception. I thought I'd send it along anyway in case the bug is obvious. Aaron Lav (a...@pobox.com)
Index: java/org/osafoundation/lucene/queryParser/PythonQueryParser.java =================================================================== --- java/org/osafoundation/lucene/queryParser/PythonQueryParser.java (revision 15091) +++ java/org/osafoundation/lucene/queryParser/PythonQueryParser.java (working copy) @@ -17,7 +17,7 @@ package org.osafoundation.lucene.queryParser; -import java.util.Vector; +import java.util.List; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.search.Query; @@ -56,7 +56,7 @@ } public native void pythonDecRef(); - public native Query getBooleanQuery(Vector clauses); + public native Query getBooleanQuery(List clauses, boolean disableCoord); public native Query getFieldQuery(String field, String queryText); public native Query getFieldQuery(String field, String queryText, int slop); public native Query getFuzzyQuery(String field, String termText,
# ==================================================================== # Copyright (c) 2004-2008 Open Source Applications Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ==================================================================== from unittest import TestCase, main from lucene import * class BooleanTestMixin(object): def getBooleanQuery(self, clauses, disableCoord): extra_query = TermQuery(Term("all", "extra_clause")) extra_clause = BooleanClause(extra_query, BooleanClause.Occur.SHOULD) clauses.add(extra_clause) return super(BooleanTestMixin, self).getBooleanQuery(clauses, disableCoord) class PythonQueryParserTestCase(TestCase): def testOverrideBooleanQuery(self): class TestQueryParser(BooleanTestMixin,PythonQueryParser): pass qp = TestQueryParser('all', StandardAnalyzer()) q = qp.parse("foo bar") self.assertEquals(str(q), "all:foo all:bar all:extra_clause") class PythonMultiFieldQueryParserTestCase(TestCase): def testOverrideBooleanQuery(self): class TestQueryParser(BooleanTestMixin,PythonMultiFieldQueryParser): pass # instantiating TestQueryParser or PythonMultiFieldQueryParser # doesn't work (yields a java.lang.NullPointerException) qp = TestQueryParser(['one', 'two'], StandardAnalyzer()) # qp = PythonMultiFieldQueryParser(['one', 'two'], StandardAnalyzer()) # qp = MultiFieldQueryParser(['one', 'two'], StandardAnalyzer()) q = qp.parse(qp,"foo bar") self.assertEquals(str(q), "(one:foo two:foo) (one:bar two:bar) all:extra_clause") if __name__ == "__main__": import sys initVM(CLASSPATH) if '-loop' in sys.argv: sys.argv.remove('-loop') while True: try: main() except: pass else: main()