Exemple #1
0
}
try {
    // Open the database for searching.
    $database = new XapianDatabase($argv[1]);
    // Start an enquire session.
    $enquire = new XapianEnquire($database);
    // Combine command line arguments up to "--" with spaces between
    // them, so that simple queries don't have to be quoted at the shell
    // level.
    $args = array_slice($argv, 2);
    $separator = array_search("--", $args);
    if ($separator === FALSE) {
        $separator = count($args);
    }
    $query_string = join(" ", array_slice($args, 0, $separator));
    $rset = new XapianRSet();
    foreach (array_slice($args, $separator + 1) as $docid) {
        $rset->add_document(intval($docid));
    }
    $qp = new XapianQueryParser();
    $stemmer = new XapianStem("english");
    $qp->set_stemmer($stemmer);
    $qp->set_database($database);
    $qp->set_stemming_strategy(XapianQueryParser::STEM_SOME);
    $query = $qp->parse_query($query_string);
    print "Parsed query is: {$query->get_description()}\n";
    // Find the top 10 results for the query.
    $enquire->set_query($query);
    $matches = $enquire->get_mset(0, 10, $rset);
    // Display the results.
    print "{$matches->get_matches_estimated()} results found:\n";
        exit(1);
    }
    if ($mset->get_docid(0) != 2) {
        print "MatchDecider mset has wrong docid in\n";
        exit(1);
    }
}
class testexpanddecider extends XapianExpandDecider
{
    function apply($term)
    {
        return $term[0] !== 'a';
    }
}
$enquire = new XapianEnquire($db);
$rset = new XapianRSet();
$rset->add_document(1);
$eset = $enquire->get_eset(10, $rset, XapianEnquire::USE_EXACT_TERMFREQ, 1.0, new testexpanddecider());
foreach ($eset->begin() as $t) {
    if ($t[0] === 'a') {
        print "XapianExpandDecider was not used\n";
        exit(1);
    }
}
# Check min_wt argument to get_eset() works (new in 1.2.5).
$eset = $enquire->get_eset(100, $rset, XapianEnquire::USE_EXACT_TERMFREQ);
$min_wt = 0;
foreach ($eset->begin() as $i => $dummy) {
    $min_wt = $i->get_weight();
}
if ($min_wt >= 1.9) {