Ticket #488: xapian-php-matchdecider.patch

File xapian-php-matchdecider.patch, 1.7 KB (added by Olly Betts, 14 years ago)

patch which enables directors and adds a feature test

  • php/smoketest.php

     
    145145    exit(1);
    146146}
    147147
     148# Feature test for MatchDecider
     149$doc = new XapianDocument();
     150$doc->set_data("Two");
     151$doc->add_posting($stem->apply("out"), 1);
     152$doc->add_posting($stem->apply("outside"), 1);
     153$doc->add_posting($stem->apply("source"), 2);
     154$doc->add_value(0, "yes");
     155$db->add_document($doc);
     156
     157class testmatchdecider extends XapianMatchDecider {
     158    function apply($doc) {
     159        # FIXME: workaround missing object wrapping in generated wrappers.
     160        if (is_resource($doc)) $doc = new XapianDocument($doc);
     161        return ($doc->get_value(0) == "yes");
     162    }
     163}
     164
     165$query = new XapianQuery($stem->apply("out"));
     166$enquire = new XapianEnquire($db);
     167$enquire->set_query($query);
     168$mdecider = new testmatchdecider();
     169$mset = $enquire->get_mset(0, 10, null, $mdecider);
     170if ($mset->size() != 1) {
     171    print "Unexpected number of documents returned by match decider (".$mset->size().")\n";
     172    exit(1);
     173}
     174if ($mset->get_docid(0) != 2) {
     175    print "MatchDecider mset has wrong docid in\n";
     176}
     177
    148178if (XapianQuery::OP_ELITE_SET != 10) {
    149179    print "OP_ELITE_SET is XapianQuery::OP_ELITE_SET not 10\n";
    150180    exit(1);
  • php/util.i

     
    2828#include "../xapian-version.h"
    2929%}
    3030
     31// Use SWIG directors for PHP wrappers.
     32#define XAPIAN_SWIG_DIRECTORS
     33
    3134/* Add a section to the output from phpinfo(). */
    3235%pragma(php) phpinfo="
    3336    const char * linked_version = Xapian::version_string();