日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php怎么样sphinx,php使用sphinx

發布時間:2023/12/19 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php怎么样sphinx,php使用sphinx 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2.使用sphinx php api測試:<?php

require ( "sphinxapi.php" ); //此文件在sphinx源代碼的api文件夾中可以找到

$cl = new SphinxClient ();

$q = "weibo";

$sql = "test1";

$mode = SPH_MATCH_ALL;

$host = "localhost";

$port = 9312;

$index = "*";

// $groupby = "";

// $groupsort = "@group desc";

// $filter = "group_id";

// $filtervals = array();

// $distinct = "";

// $sortby = "";

// $sortexpr = "";

// $limit = 20;

// $ranker = SPH_RANK_PROXIMITY_BM25;

// $select = "";

$cl->SetServer ( $host, $port );

$cl->SetConnectTimeout ( 1 );

$cl->SetArrayResult ( true );

$cl->SetMatchMode ( $mode );

// if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );

// if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );

// if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );

// if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );

// if ( $distinct ) $cl->SetGroupDistinct ( $distinct );

// if ( $select ) $cl->SetSelect ( $select );

// if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );

//$cl->SetRankingMode ( $ranker );

$res = $cl->Query ( $q, $index );

// print me out

if ( $res===false )

{

print "Query failed: " . $cl->GetLastError() . ".
";

} else

{

if ( $cl->GetLastWarning() )

print "WARNING: " . $cl->GetLastWarning() . "
";

print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.
";

print "Query stats:
";

if ( is_array($res["words"]) )

foreach ( $res["words"] as $word => $info )

print " '$word' found $info[hits] times in $info[docs] documents\n";

print "
";

if ( is_array($res["matches"]) )

{

$n = 1;

print "Matches:
";

foreach ( $res["matches"] as $docinfo )

{

print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";

foreach ( $res["attrs"] as $attrname => $attrtype )

{

$value = $docinfo["attrs"][$attrname];

if ( $attrtype==SPH_ATTR_MULTI || $attrtype==SPH_ATTR_MULTI64 )

{

$value = "(" . join ( ",", $value ) .")";

} else

{

if ( $attrtype==SPH_ATTR_TIMESTAMP )

$value = date ( "Y-m-d H:i:s", $value );

}

print ", $attrname=$value";

}

print "
";

$n++;

}

}

}

?>

打印的結果:Query 'weibo' retrieved 1000 of 3873 matches in 0.001 sec.

Query stats:

'weibo' found 3873 times in 3873 documents

Matches:

1. doc_id=1, weight=1, import_timestamp=2015-06-26 16:25:41

2. doc_id=4, weight=1, import_timestamp=2015-06-26 16:25:41

3. doc_id=5, weight=1, import_timestamp=2015-06-26 16:25:41

4. doc_id=6, weight=1, import_timestamp=2015-06-26 16:25:41

5. doc_id=8, weight=1, import_timestamp=2015-06-26 16:25:41

6. doc_id=9, weight=1, import_timestamp=2015-06-26 16:25:41

7. doc_id=10, weight=1, import_timestamp=2015-06-26 16:25:41

8. doc_id=11, weight=1, import_timestamp=2015-06-26 16:25:41

9. doc_id=12, weight=1, import_timestamp=2015-06-26 16:25:41

10. doc_id=13, weight=1, import_timestamp=2015-06-26 16:25:41

11. doc_id=14, weight=1, import_timestamp=2015-06-26 16:25:41

12. doc_id=15, weight=1, import_timestamp=2015-06-26 16:25:41

13. doc_id=16, weight=1, import_timestamp=2015-06-26 16:25:41

14. doc_id=17, weight=1, import_timestamp=2015-06-26 16:25:41

15. doc_id=18, weight=1, import_timestamp=2015-06-26 16:25:41

16. doc_id=19, weight=1, import_timestamp=2015-06-26 16:25:41

17. doc_id=20, weight=1, import_timestamp=2015-06-26 16:25:41

18. doc_id=21, weight=1, import_timestamp=2015-06-26 16:25:41

19. doc_id=22, weight=1, import_timestamp=2015-06-26 16:25:41

20. doc_id=23, weight=1, import_timestamp=2015-06-26 16:25:41

總結

以上是生活随笔為你收集整理的php怎么样sphinx,php使用sphinx的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。