• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

xapian按照数字范围进行检索的php范例代码

PHP 水墨上仙 1630次浏览

xapian按照数字范围进行检索的php范例代码,对通过add_value方法添加的属性进行范围搜索。

<?php
if (php_sapi_name() != "cli") {
    print "This example script is written to run under the command line ('cli') version of\n";
    print "the PHP interpreter, but you're using the '".php_sapi_name()."' version\n";
    exit(1);
}
include "xapian.php";
if ($argc != 2) {
    print "Usage: {$argv[0]} PATH_TO_DATABASE\n";
    exit(1);
}
try {
    // Open the database for update, creating a new database if necessary.
    $database = new XapianWritableDatabase($argv[1], Xapian::DB_CREATE_OR_OVERWRITE);
    // add a document with a term and a timestamp value
    $doc = new XapianDocument();
    $doc->add_term("foo");
    $doc->add_value(1, Xapian::sortable_serialise(1000000000));
    $database->add_document($doc);
    // add another: same term, different timestamp value
    $doc = new XapianDocument();
    $doc->add_term("foo");
    $doc->add_value(1, Xapian::sortable_serialise(2000000000));
    $database->add_document($doc);
    // Set the database handle to Null to ensure that it gets closed
    // down cleanly or unflushed changes may be lost.
    $database = Null;
    // open database for reading
    $database = new XapianDatabase($argv[1]);
    $enquire = new XapianEnquire($database);
    // example 1 using a query processor
    $qp = new XapianQueryParser();
    $qp->set_database($database);
    $datenumproc = new XapianNumberValueRangeProcessor(1);
    $qp->add_valuerangeprocessor($datenumproc);
    // without range: get both docs
    $query = $qp->parse_query("foo");
    $enquire->set_query($query);
    print $enquire->get_mset(0, 10)->size();
    print "\n";
    // with range: get first doc
    $query = $qp->parse_query("foo 1000000000..1500000000");
    $enquire->set_query($query);
    print $enquire->get_mset(0, 10)->size();
    print "\n";
    // example 2 - direct query construction (get first doc)
    $query = new XapianQuery(XapianQuery::OP_VALUE_RANGE, 
                             1,
                             Xapian::sortable_serialise(1000000000),
                             Xapian::sortable_serialise(1500000000));
    $enquire->set_query($query);
    print $enquire->get_mset(0, 10)->size();
    print "\n";
} catch (Exception $e) {
    print $e->getMessage() . "\n";
    exit(1);
}
?>


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明xapian按照数字范围进行检索的php范例代码
喜欢 (0)
加载中……