Hello! I just started playing around with Xapian using the php bindings and am having some trouble getting the term positions for terms returned by a query. The code I'm currently using reads like so: $database = new XapianDatabase("/tmp/xapian"); $enquire = new XapianEnquire($database); ... $enquire->set_query($query); $matches = $enquire->get_mset(0, 50); ... $i = $matches->begin(); while (!$i->equals($matches->end())) { $curdoc = $i->get_document(); $terms = $enquire->get_matching_terms_begin($curdoc->get_docid()); while (!$terms->equals($enquire->get_matching_terms_end($curdoc->get_docid()))) { $curterm = $terms->get_term(); $pos = $terms->positionlist_begin(); while (!$pos->equals($terms->positionlist_end())) { $curpos = $pos->get_termpos(); echo " - " . $curpos; $pos->next(); } $terms->next(); } $i->next(); } When I run the script, I get this: "InvalidOperationError: VectorTermList::positionlist_begin() isn't meaningful" I tried using $database->positionlist_begin($curdoc->get_docid(), $curterm) as well, but when I used that the while loop simply didn't run. Anyway, I'm probably making some stupid error, but if you have any ideas I'd love to be able to get the term positions. I didn't see anything in the archives about this :( Thanks, -Mike
On Sun, Aug 19, 2007 at 10:53:18PM -0500, Mike Ragalie wrote:> I just started playing around with Xapian using the php bindings and am > having some trouble getting the term positions for terms returned by a > query. > [snip] > When I run the script, I get this: "InvalidOperationError: > VectorTermList::positionlist_begin() isn't meaningful"This isn't supported (at the C++ level). It's unclear to me what the most natural semantics would be. It wouldn't be too hard for it just to return all the positions at which the term occurred, but perhaps it's more natural for it to return the positions which were relevant to the query run (so for a phrase search it would only show where the the term matched as part of the phrase). That's not something we currently know, so we'd have to write the code to work this out.> I tried using $database->positionlist_begin($curdoc->get_docid(), $curterm) > as well, but when I used that the while loop simply didn't run.That should work if you want all the positions. It's hard to say why it didn't for you without seeing the code you had. Here's a post with some suitable C++ code if that helps: http://article.gmane.org/gmane.comp.search.xapian.general/2187 Cheers, Olly