因爲在win8.1下安裝 選的這個版本php
Win64 binaries w/MySQL+PgSQL+libstemmer+id64 support | 2.2.6-release | 7.3M |
下載頁面mysql
http://sphinxsearch.com/downloads/release/sql
1.編輯配置文件api
下載完 解壓 到其中一個目錄下post
首先配置sphinx 配置文件 解壓後sphinx目錄下有個sphinx.conf.in 複製到bin目錄下 並更名 sphinx.conf測試
配置以下 須要改的幾個參數 稍微整理下 在發出ui
2.安裝步驟編碼
2.1 安裝服務 啓動守護進程
D:\www\Sphinx\bin>searchd --install --config D:\www\Sphinx\bin\sphinx.conf --servicename Sphinx
Sphinx 2.2.6-id64-release (r4843)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)spa
Installing service...
Service 'Sphinx' installed successfully.code
2.2 創建索引
D:\www\Sphinx\bin>indexer.exe --all
Sphinx 2.2.6-id64-release (r4843)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file './sphinx.conf'...
indexing index 'test1'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 173 bytes
total 0.161 sec, 1073 bytes/sec, 18.61 docs/sec
indexing index 'test1stemmed'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 173 bytes
total 0.061 sec, 2824 bytes/sec, 48.98 docs/sec
skipping non-plain index 'rt'...
total 6 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 24 writes, 0.001 sec, 0.1 kb/call avg, 0.0 msec/call avg
2.3 開啓服務
D:\www\Sphinx\bin>net start Sphinx
Sphinx 服務正在啓動 .
Sphinx 服務已經啓動成功。
20160828中止Sphinx服務 net stop Sphinx
C:\Windows\System32\cmd.exe 右鍵管理員權限執行
PS:按照順序纔是正確的
3.測試搜索
用的官方API事例調用的 不過有些問題 我把如今改的先發上來參考 還有些沒弄明白
1 <?php 2 require ( "sphinxapi.php" ); 3 $cl = new SphinxClient (); 4 $q = "模型"; 5 $sql = ""; 6 $mode = SPH_MATCH_ALL; 7 $host = "127.0.0.1"; 8 $port = 9312; 9 $index = "*"; 10 $groupby = ""; 11 $groupsort = "@group desc"; 12 $filter = "id"; 13 $filtervals = array(); 14 $distinct = ""; 15 $sortby = ""; 16 $sortexpr = ""; 17 $limit = 20; 18 $ranker = SPH_RANK_PROXIMITY_BM25; 19 $select = ""; 20 21 $cl->SetServer ( $host, $port ); 22 $cl->SetConnectTimeout ( 1 ); 23 24 $cl->SetArrayResult ( true ); 25 26 $cl->SetRankingMode ( $ranker ); 27 $res = $cl->Query ( $q, $index ); 28 var_dump($res); 29 30 if ( $res===false ) 31 { 32 print "Query failed: " . $cl->GetLastError() . ".\n"; 33 34 } else 35 { 36 if ( is_array($res["matches"]) ) 37 { 38 $n = 1; 39 print "Matches:\n"; 40 41 42 foreach ( $res["matches"] as $docinfo ) 43 { 44 print "$n. id=$docinfo[id], weight=$docinfo[weight]"; 45 print "\n"; 46 47 foreach ( $res["attrs"] as $attrname => $attrtype ) 48 { 49 50 $value = $docinfo["attrs"][$attrname]; 51 52 if ( $attrtype==SPH_ATTR_MULTI || $attrtype==SPH_ATTR_MULTI64 ) 53 { 54 55 $value = "(" . join ( ",", $value ) .")"; 56 57 } else 58 { 59 if ( $attrtype==SPH_ATTR_TIMESTAMP ) 60 $value = date ( "Y-m-d H:i:s", $value ); 61 62 63 } 64 print ", $attrname=$value"; 65 } 66 print "\n"; 67 $n++; 68 } 69 } 70 71 72 } 73 ?>
搜索獲得的結果是這樣的
array(10) {
["error"]=>
string(0) ""
["warning"]=>
string(0) ""
["status"]=>
int(0)
["fields"]=>
array(8) {
[0]=>
string(8) "pictitle"
[1]=>
string(10) "picsubhead"
[2]=>
string(11) "piccategroy"
[3]=>
string(6) "pictag"
[4]=>
string(8) "picalbum"
[5]=>
string(9) "picauthor"
[6]=>
string(14) "picdescription"
[7]=>
string(8) "picmusic"
}
["attrs"]=>
array(7) {
["pictitle"]=>
int(7)
["picposttime"]=>
int(2)
["picsubhead"]=>
int(7)
["piccategroy"]=>
int(7)
["pictag"]=>
int(7)
["picdescription"]=>
int(7)
["picmusic"]=>
int(7)
}
["matches"]=>
array(1) {
[0]=>
array(3) {
["id"]=>
int(11)
["weight"]=>
string(4) "2680"
["attrs"]=>
array(7) {
["pictitle"]=>
string(7) "test111"
["picposttime"]=>
string(10) "1417853738"
["picsubhead"]=>
string(8) "fubiaoti"
["piccategroy"]=>
string(6) "模型"
["pictag"]=>
string(8) "zidingyi"
["picdescription"]=>
string(7) "picture"
["picmusic"]=>
string(20) "http://www.baidu.com"
}
}
}
["total"]=>
string(1) "1"
["total_found"]=>
string(1) "1"
["time"]=>
string(5) "0.000"
["words"]=>
array(2) {
["模"]=>
array(2) {
["docs"]=>
string(1) "2"
["hits"]=>
string(1) "2"
}
["型"]=>
array(2) {
["docs"]=>
string(1) "2"
["hits"]=>
string(1) "2"
}
}
}
Matches:
1. id=11, weight=2680
, pictitle=test111, picposttime=2014-12-06 16:15:38, picsubhead=fubiaoti, piccategroy=模型, pictag=zidingyi, picdescription=picture, picmusic=http://www.baidu.com
中文詞典這些屬性設置已經移除charset_dictpath 剩下的 等我研究好了 繼續發佈
在版本升級中 重點的東西提下
在2.2.1-beta版本下
官方推薦使用 SphinxQL
SphinxAPI and Sphinx SE之後將會被移除
在 2.2.2-beta版本中
移除了CLI search 之前版本的 search 命名不可用 bin目錄下也沒有search.exe
反對使用SetMatchMode() API
移除了charset_type and mssql_unicod設置 只支持UTF-8編碼
PS: 2.2.6 默認開始了
listen = 9306:mysql41 啓用了SphinxQL 而且ID默認都是64位