找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 520|回复: 4

Sphinx 读取ID列表演示PHP代码

[复制链接]
发表于 2011-8-1 16:58:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. <?php
  2. // --------------------------------------------------------------------------
  3. // File name : test_coreseek.php
  4. // Description : coreseek中文全文检索系统测试程序
  5. // Requirement : PHP5 (http://www.php.net)
  6. //
  7. // Copyright(C), HonestQiao, 2011, All Rights Reserved.
  8. //
  9. // Author: HonestQiao (honestqiao@gmail.com)
  10. //
  11. // 最新使用文档,请查看:http://www.coreseek.cn/products/products-install/
  12. //
  13. // --------------------------------------------------------------------------

  14. require ( "sphinxapi.php" );

  15. $cl = new SphinxClient ();
  16. $cl->SetServer ( '127.0.0.1', 9312);
  17. $cl->SetConnectTimeout ( 3 );
  18. $cl->SetArrayResult ( true );
  19. $cl->SetMatchMode ( SPH_MATCH_ANY);
  20. $cl->SetLimits(0,20); //取从头开始的前20条数据,0,20类似SQl语句的LIMIT 0,20
  21. $res = $cl->Query ( '网络搜索', "*" );
  22. print_r($cl);
  23. print_r($res);

  24. printf("错误信息:%s
  25. ",$cl->GetLastError());
  26. printf("告警信息:%s
  27. ",$cl->GetLastWarning());

  28. printf("信息总数:%d
  29. ", $res['total_found']);
  30. printf("本页条数:%d
  31. ", $res['total']);

  32. if($res['total'])
  33. {
  34. $ids = $res['matches'];
  35. array_walk($ids,create_function('&$item','$item = $item["id"];'));
  36. $idstr = implode(',',$ids);
  37. printf("ID列表:%s
  38. ",$idstr);

  39. printf("查询结果:
  40. ");
  41. mysql_connect('localhost','root','123456');
  42. mysql_select_db('test');
  43. mysql_query('SET NAMES utf8');
  44. $query = "SELECT * FROM documents WHERE id IN ($idstr) ORDER BY id DESC";
  45. $res = mysql_query($query);
  46. while($row = mysql_fetch_assoc($res)){
  47. printf("id=%d title=%s
  48. ",$row['id'],$row['title']);
  49. }
  50. }
复制代码



发表于 2011-8-1 20:23:04 | 显示全部楼层
看来PHP和ASPX相差很大啊,我就看懂一点点。。。
 楼主| 发表于 2011-8-1 23:05:56 | 显示全部楼层
呵呵,看下应该就会明白许多了吧
 楼主| 发表于 2011-8-1 23:06:09 | 显示全部楼层
鳳凰の馨蘭寺 发表于 2011-8-1 20:23
看来PHP和ASPX相差很大啊,我就看懂一点点。。。

呵呵,看下应该就会明白许多了吧
发表于 2011-8-8 22:16:38 | 显示全部楼层
ding呀 支持



















夜晨影院 影视界 正味网
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部快速回复上一主题下一主题返回列表找客服手机访问

QQ|申请友链|Archiver|小黑屋|手机版|网站地图|谷姐论坛 谷姐提供 ( 渝ICP备2021009247号-1 )

GMT+8, 2024-6-2 08:32

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表