[Xapian-discuss] PHP termpos issue

Mike Ragalie ragalie at fas.harvard.edu
Mon Aug 20 04:53:18 BST 2007


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


More information about the Xapian-discuss mailing list