Hi all, I'm pretty new to xapian and I can't seem to see what's wrong with this code. 1 ''' 2 This module provides some examples of how to use the xapian API 3 ''' 4 5 import xapian 6 def test_near(): 7 xapian.Query(xapian.Query.OP_PHRASE, 'abc', 'def') 8 q_phrase = xapian.Query(xapian.Query.OP_PHRASE, ("smoke", "test", "tuple")) 9 q_xor = xapian.Query(xapian.Query.OP_XOR, (xapian.Query('smoke'), q_phrase, 'string')) 10 q_phrase_comp = xapian.Query(xapian.Query.OP_PHRASE, (q_phrase, q_xor)) The query in line 10 bombs out with: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/case.py", line 52, in runTest self.testFunc() File "/Users/victorng/dev/bzr_repo/test_xapian.py", line 10, in test_near q_phrase_comp = xapian.Query(xapian.Query.OP_PHRASE, (q_phrase, q_xor)) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/xapian.py", line 473, in __init__ _xapian.Query_swiginit(self,_xapian.new_Query(*args)) RuntimeError: unknown error in Xapian Aren't PHRASE queries allowed to take arbitrary subqueries or does it only allow some kinds of subqueries? vic
Richard Boulton
2007-Mar-15 11:51 UTC
[Xapian-discuss] Phrase query problem with python api
Victor Ng wrote:> line 473, in __init__ > _xapian.Query_swiginit(self,_xapian.new_Query(*args)) > RuntimeError: unknown error in Xapian > > > Aren't PHRASE queries allowed to take arbitrary subqueries or does it > only allow some kinds of subqueries?PHRASE queries aren't allowed to contain subqueries which are PHRASE or NEAR subqueries. In SVN Xapian, the exception message from your code is more helpful: xapian.UnimplementedError: Can't use NEAR/PHRASE with a subexpression containing NEAR or PHRASE Actually, if I recall correctly, NEAR and PHRASE pretty much only accept single-term subqueries currently, though I may be out of date on this point. I've never needed to perform these kinds of queries - if you can find examples of real-world queries which need support for this, it might encourage someone to develop support for it sooner rather than later. -- Richard