加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

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

发布时间:2020-05-25 05:42:03 所属栏目:PHP 来源:互联网
导读: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 ofn";
	print "the PHP interpreter,but you're using the '".php_sapi_name()."' versionn";
	exit(1);
}
include "xapian.php";
if ($argc != 2) {
	print "Usage: {$argv[0]} PATH_TO_DATABASEn";
	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)   ***/

 

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读