3.1.1版本安裝
參考:http://sphinxsearch.com/docs/sphinx3.html
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2csETSE10MNpXT5F1MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnL3EDOzEjMwIjM4EzMwkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
我安裝的3.1.1版本
啟動報錯:no config file, using 'sphinxdata' folder...
參考:https://www.jianshu.com/p/f12c7301a0fd
解決:沒有配置檔案啟動,自動在bin目錄下建立sphinxdata目錄啟動
移動到/usr/local/sphinx
mv sphinx-3.1.1 /usr/local/sphinx
複制一個簡單版配置檔案:
cp /usr/local/sphinx/etc/sphinx-min.conf.dist /usr/local/sphinx/etc/sphinx.conf
配置資料目錄
mkdir /usr/local/sphinx/data
連接配接資料庫使用示例/usr/local/sphinx/etc/example.sql檔案到test資料庫下建立兩個表
mysql>use test
mysql>source /usr/local/sphinx/etc/example.sql
建立索引,--rotate 參數進行 無縫更新,無需重新開機服務
全部:/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate
單個(test1為索引名稱):/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf test1
建立單個test1索引報錯:ERROR: index 'test1': sql_connect: failed to load libmysqlclient
參考:http://sphinxsearch.com/docs/sphinx3.html
解決:yum install mariadb-devel
再次建立索引又報錯:ERROR: index 'test1': sql_connect: Can't connect to local MySQL server through socket
解決:修改mysql配置項用sock連接配接
建立索引成功,data目錄下生成很多索引檔案:
用配置檔案啟動
/usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf
phpdemo測試:
主查詢,查詢出所有在檢索範圍的資料,以關鍵詞為 'test' 做測試
php執行個體代碼,官方sphinxapi.php檔案在目錄api下面有:
命中的搜尋資料: