用PHP和xapian构建全文检索
浏览:3416次 出处信息
index.php
- <?php
- require_once 'XapianWrapper.php';
- $x = new XapianWrapper();
- $res = $x->index(array());
- print_r($res);
Search.php
- <?php
- require_once 'XapianWrapper.php';
- $x = new XapianWrapper();
- $params = array('search' => 'foo');
- $res = $x->search($params);
- print_r($res);
delete.php
- <?php
- require_once 'XapianWrapper.php';
- $x = new XapianWrapper();
- $params = array(
- 'items' => array('foo'),
- );
- $res = $x->delete($params);
- print_r($res);
使用示例:
您下载刚才的源码包后,就可以导入db.sql,并在命令里运行程序;
- bash$ php index.php
- stdClass Object
- (
- [indexed] => Array
- (
- [0] => Array
- (
- [name] => foo
- [guid] => foo
- [url] =>
- )
- [1] => Array
- (
- [name] => bar
- [guid] => bar
- [url] =>
- )
- )
- )
- bash$ php search.php
- stdClass Object
- (
- [result_count] => 2
- [results] => Array
- (
- [0] => Array
- (
- [position] => 1
- [url] =>
- [name] => foo
- [summary] => foo bar test
- [date] => 20081105
- [unique_key] => foo
- [percent] => 100
- )
- [1] => Array
- (
- [position] => 2
- [url] =>
- [name] => bar
- [summary] => test foo bar
- [date] => 20091105
- [unique_key] => bar
- [percent] => 50
- )
- )
- [execute] => stdClass Object
- (
- [call] => search
- [offset] => 0
- [count] => 10
- [start] => 1256674866.79
- [end] => 1256674866.79
- [time] => 0.000944852828979
- [debug] => Xapian::Query(Zfoo:(pos=1))
- )
- )
- bash$ php delete.php
- Array
- (
- [0] => foo
- )
- bash$ php search.php
- stdClass Object
- (
- [result_count] => 1
- [results] => Array
- (
- [0] => Array
- (
- [position] => 1
- [url] =>
- [name] => bar
- [summary] => test foo bar
- [date] => 20091105
- [unique_key] => bar
- [percent] => 100
- )
- )
- [execute] => stdClass Object
- (
- [call] => search
- [offset] => 0
- [count] => 10
- [start] => 1256674876.02
- [end] => 1256674876.02
- [time] => 0.000872850418091
- [debug] => Xapian::Query(Zfoo:(pos=1))
- )
- )
接下来,扩展您自己的程序来满足您的各种需求吧,欢迎反馈.好好地享受检索的乐趣吧.
建议继续学习:
- Xapian搜索体系结构 (阅读:4006)
- Hermes:来自腾讯的实时检索分析平台 (阅读:2942)
- Xapian的查询分析器 (阅读:2741)
- 基于Lucene/XML的站内全文检索解决方案:WebLucene (阅读:2457)
- 检测文本正文是否包含有特定词的PHP扩展 (阅读:2445)
- 利用Sphinx实现实时全文检索 (阅读:2374)
- Xapian 术语表 (阅读:2236)
- 分布式全文检索系统SolrCloud简介 (阅读:1786)
- 检索结果聚类展望 (阅读:1767)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习