<?php include_once 'sphinxapi.php'; $s = new SphinxClient(); $s->setServer("localhost", 9312); $s->SetConnectTimeout ( 1 );//设置链接超时 /* $s->AddQuery();//列表查询 $s->RunQueries ();//执行列表查询 $s->ResetFilters();//清除过滤条件 $s->BuildExcerpts($docs, $index, $words);//生成简要 $s->BuildKeywords($query, $index, $hits);//生成关键字 $s->GetLastError();//错误 $s->GetLastWarning();//警告 $s->FlushAttributes();//索引刷入硬盘 $s->IsConnectError();//链接错误 $s->ResetGroupBy();//重设分组 $s->SetFieldWeights(array('sub_title'=>1));//加权最小为1 $s->SetIDRange($min, $max);//ID范围 $s->SetIndexWeights(array('test1'=>1));//索引权重 $s->Status();//服务是否可用 $s->UpdateAttributes($index, $attrs, $values);//更新硬盘索引 */ /* 参考文档:http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html#matching-modes SPH_MATCH_ALL, matches all query words (default mode); SPH_MATCH_ANY, matches any of the query words; SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match; SPH_MATCH_BOOLEAN, matches query as a boolean expression (see Section 5.2, “Boolean query syntax”); SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language (see Section 5.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. SPH_MATCH_EXTENDED2, matches query using the second version of the Extended matching mode. SPH_MATCH_FULLSCAN, m */ $s->setMatchMode(SPH_MATCH_ANY);//匹配模式 $s->setMaxQueryTime(3);//查询超时 //$s->SetSelect ( $select );//设置返回的字段 /* $cl->SetSelect ( "*, @weight+(user_karma+ln(pageviews))*0.1 AS myweight" ); $cl->SetSelect ( "exp_years, salary_gbp*{$gbp_usd_rate} AS salary_usd, IF(age>40,1,0) AS over40" ); $cl->SetSelect ( "*, AVG(price) AS avgprice" ); */ /* $cl->SetGroupBy ( "category", SPH_GROUPBY_ATTR, "@count desc" ); $cl->SetGroupDistinct ( "vendor" ); == SELECT id, weight, all-attributes, COUNT(DISTINCT vendor) AS @distinct, COUNT(*) AS @count FROM products GROUP BY category ORDER BY @count DESC */ //$s->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );//汇总 //$s->SetGroupDistinct ( $distinct );//设置不重复字段 $s->SetArrayResult ( true );//结果是否有ID /* SPH_SORT_RELEVANCE mode, that sorts by relevance in descending order (best matches first); SPH_SORT_ATTR_DESC mode, that sorts by an attribute in descending order (bigger attribute values first); SPH_SORT_ATTR_ASC mode, that sorts by an attribute in ascending order (smaller attribute values first); 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; SPH_SORT_EXTENDED mode, that sorts by SQL-like combination of columns in ASC/DESC order; SPH_SORT_EXPR mode, that sorts by an arithmetic expression. */ //$s->SetSortMode ( SPH_SORT_EXTENDED, $sortby );//排序模式 /* $s->SetOverride($attrname, $attrtype, $values); $s->ResetOverrides();*/ /* $s->SetRetries($count);//设置失败重试 $s->SetRankingMode($ranker);//设置排名模式 均适用于SPH_MATCH_EXTENDED2搜索 //第3个参数当为true时,相当于$attribute!=$value,默认值是false $s->SetFilter ( 'target_type', $filtervals );//设置过滤,值列表 $s->SetFilterFloatRange($attribute, $min, $max);//浮动范围 $s->SetFilterRange($attribute, $min, $max);//指定范围 $s->SetGeoAnchor($attrlat, $attrlong, $lat, $long); */ //link //$s->SetFilter ( 'target_type', array(1),true ); $s->SetLimits ( 0, 10 );//显示数量:开始 量 最大量 右偏移量 $result = $s->query("good","team");//查询 print_r($result);