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

对xapian按照数字范围进行检索的PHP范例代码感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
xapian按照数字范围进行检索的PHP范例代码,对通过add_value方法添加属性进行范围搜索

/**
 * xapian按照数字范围进行检索的PHP范例代码
 *
 * @param 
 * @arrange 512-笔记网: jb51.cc
 **/
<?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);
}

/***   来自编程之家 jb51.cc(jb51.cc)   ***/

 

相关文章

Hessian开源的远程通讯,采用二进制 RPC的协议,基于 HTTP 传输。可以实现PHP调用Java,Python,C#等多语...
初识Mongodb的一些总结,在Mac Os X下真实搭建mongodb环境,以及分享个Mongodb管理工具,学习期间一些总结...
边看边操作,这样才能记得牢,实践是检验真理的唯一标准.光看不练假把式,光练不看傻把式,边看边练真把式....
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较。 echo与print的区别: (...
在安装好wampServer后,一直没有使用phpMyAdmin,今天用了一下,phpMyAdmin显示错误:The mbstring exte...
变量是用于存储数据的容器,与代数相似,可以给变量赋予某个确定的值(例如:$x=3)或者是赋予其它的变...