xapian php 检索,php 利用xapian按照数字范围进行检索的简单示例

这篇文章主要为大家详细介绍了php 利用xapian按照数字范围进行检索的简单示例,具有一定的参考价值,可以用来参考一下。

对xapian按照数字范围进行检索的php范例代码感兴趣的小伙伴,下面一起跟随512笔记的小编两巴掌来看看吧!

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

/**

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

*

* @param

* @arrange 512-笔记网: www.512pic.com

**/

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);

}

/*** 来自512笔记(www.512pic.com) ***/

注:关于php 利用xapian按照数字范围进行检索的简单示例的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。

关键词:xapian

您可能感兴趣的文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值