php连接coreseek

来源:互联网 发布:网络基础试题及答案 编辑:程序博客网 时间:2024/06/05 21:06
  1. <?php  
  2.  
  3. include_once 'sphinxapi.php'
  4. $s = new SphinxClient(); 
  5. $s->setServer("localhost", 9312); 
  6. $s->SetConnectTimeout ( 1 );//设置链接超时 
  7.  
  8.  
  9. /* 
  10. $s->AddQuery();//列表查询 
  11. $s->RunQueries ();//执行列表查询 
  12. $s->ResetFilters();//清除过滤条件
  13. $s->BuildExcerpts($docs, $index, $words);//生成简要 
  14. $s->BuildKeywords($query, $index, $hits);//生成关键字
  15. $s->GetLastError();//错误 
  16. $s->GetLastWarning();//警告 
  17. $s->FlushAttributes();//索引刷入硬盘 
  18. $s->IsConnectError();//链接错误 
  19. $s->ResetGroupBy();//重设分组 
  20.  
  21. $s->SetFieldWeights(array('sub_title'=>1));//加权最小为1 
  22. $s->SetIDRange($min, $max);//ID范围 
  23. $s->SetIndexWeights(array('test1'=>1));//索引权重 
  24. $s->Status();//服务是否可用 
  25. $s->UpdateAttributes($index, $attrs, $values);//更新硬盘索引 
  26. */ 
  27. /* 
  28. 参考文档:http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html#matching-modes 
  29. SPH_MATCH_ALL, matches all query words (default mode); 
  30. SPH_MATCH_ANY, matches any of the query words; 
  31. SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match; 
  32. SPH_MATCH_BOOLEAN, matches query as a boolean expression (see Section 5.2, “Boolean query syntax”); 
  33. SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language (see Section5.3, “Extended query syntax”). As of 0.9.9, this has been superceded by SPH_MATCH_EXTENDED2, providing additional functionality and better performance. The ident is retained for legacy application code that will continue to be compatible once Sphinx and its components, including the API, are upgraded. 
  34. SPH_MATCH_EXTENDED2, matches query using the second version of the Extended matching mode. 
  35. SPH_MATCH_FULLSCAN, m 
  36. */ 
  37. $s->setMatchMode(SPH_MATCH_ANY);//匹配模式 
  38. $s->setMaxQueryTime(3);//查询超时 
  39. //$s->SetSelect ( $select );//设置返回的字段 
  40. /* 
  41. $cl->SetSelect ( "*, @weight+(user_karma+ln(pageviews))*0.1 AS myweight" ); 
  42. $cl->SetSelect ( "exp_years, salary_gbp*{$gbp_usd_rate} AS salary_usd, 
  43.    IF(age>40,1,0) AS over40" ); 
  44. $cl->SetSelect ( "*, AVG(price) AS avgprice" ); 
  45. */ 
  46.  
  47. /* 
  48. $cl->SetGroupBy ( "category", SPH_GROUPBY_ATTR,"@count desc" ); 
  49. $cl->SetGroupDistinct ( "vendor" ); 
  50. == 
  51. SELECT id, weight, all-attributes, 
  52.     COUNT(DISTINCT vendor) AS @distinct, 
  53.     COUNT(*) AS @count 
  54. FROM products 
  55. GROUP BY category 
  56. ORDER BY @count DESC 
  57. */ 
  58. //$s->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );//汇总 
  59. //$s->SetGroupDistinct ( $distinct );//设置不重复字段 
  60.  
  61. $s->SetArrayResult ( true );//结果是否有ID 
  62.  
  63. /* 
  64.     SPH_SORT_RELEVANCE mode, that sorts by relevance in descending order (best matches first); 
  65.     SPH_SORT_ATTR_DESC mode, that sorts by an attribute in descending order (bigger attribute values first); 
  66.     SPH_SORT_ATTR_ASC mode, that sorts by an attribute in ascending order (smaller attribute values first); 
  67.     SPH_SORT_TIME_SEGMENTS mode, that sorts by time segments (last hour/day/week/month) in descending order, and then by relevance in descending order; 
  68.     SPH_SORT_EXTENDED mode, that sorts by SQL-like combination of columns in ASC/DESC order; 
  69.     SPH_SORT_EXPR mode, that sorts by an arithmetic expression. 
  70. */ 
  71. //$s->SetSortMode ( SPH_SORT_EXTENDED, $sortby );//排序模式 
  72.  
  73. /* 
  74. $s->SetOverride($attrname, $attrtype, $values); 
  75. $s->ResetOverrides();*/ 
  76. /* 
  77. $s->SetRetries($count);//设置失败重试 
  78. $s->SetRankingMode($ranker);//设置排名模式 均适用于SPH_MATCH_EXTENDED2搜索 
  79.  
  80. //第3个参数当为true时,相当于$attribute!=$value,默认值是false 
  81. $s->SetFilter ( 'target_type', $filtervals );//设置过滤,值列表 
  82. $s->SetFilterFloatRange($attribute, $min, $max);//浮动范围 
  83. $s->SetFilterRange($attribute, $min, $max);//指定范围 
  84. $s->SetGeoAnchor($attrlat, $attrlong, $lat, $long); 
  85. */ 
  86. //link 
  87. //$s->SetFilter ( 'target_type', array(1),true ); 
  88.  
  89.  
  90. $s->SetLimits ( 0, 10 );//显示数量:开始 量 最大量 右偏移量 
  91. $result = $s->query("good","team");//查询 
  92.  
  93.  
  94. print_r($result); 
原创粉丝点击