[Xapian-discuss] constructing phrase queries

gervin23 gervin23 at fastmail.fm
Wed Sep 29 10:29:29 BST 2004


i've been playing with constructing my own queries without the help of 
queryparser(). one thing i don't get is how to construct a phrase with 3 
or more terms.

all the python examples OR the terms like:
--------
for term in sys.argv[2:]:
   nextquery = xapian.Query(stemmer.stem_word(term.lower()))
   if topquery==None:
     topquery = nextquery
   else:
     topquery = xapian.Query(xapian.Query.OP_OR, topquery, nextquery)
query = topquery
--------

however, trying this with OP_PHRASE gives overload errors. i've tried 
placing iterators but get the same error. i'm probably way off the mark 
in understanding this but here's what i have so far:
--------
blah1 = xapian.Query('president',1,1)
blah2 = xapian.Query('yassir',1,2)
blah3 = xapian.Query(xapian.Query.OP_AND, blah1, blah2)
blah4 = xapian.Query('arafat',1,3)
blah5 = xapian.Query(xapian.Query.OP_AND, blah3, blah4)
iterbegin = xapian.TermIterator(blah5.get_terms_begin())
iterend = xapian.TermIterator(blah5.get_terms_end())
blah7 = xapian.Query(xapian.Query.OP_PHRASE, iterbegin, iterend)
blah7.set_window(3)
enquire.set_query(blah7)
--------

any help would be amazingly appreciated.

thanks,
andrew



More information about the Xapian-discuss mailing list