導航:首頁 > 編程語言 > sphinxphpmysql

sphinxphpmysql

發布時間:2023-01-19 00:48:18

『壹』 sphinxapi.php的SetSortMode()怎麼用啊

如果你是用sphinx查詢出id數組,

再到mysql中

select*fromtable1whereidin(id1,id2,...)

這樣查詢出結果,

需要注意在mysql中加上order語法:

select*fromtable1whereidin(id1,id2,...)whereidin(id1,id2,...)
orderbyfield(id,id1,id2,...)

order by field(id, id1,id2, ...)

ps: 抱歉,我來晚了~

『貳』 sphinx和solr哪個更適合php站點

建議使用Elasticsearch和solr一樣,使用lucene
這個和php無關,因為無論哪個工具,都是通過網路介面查詢,所以不回答有關是否適合php的情況~~

## ES 缺點
基於java,會有一些java的常見問題需要注意,比如gc
單純執行速度上比C寫的sphinx慢

## sphinx 優點
純粹,沒有什麼花哨的其他功能
C寫的,速度快
新版本加了分布式、動態更新索引等功能

## 下面列舉Es比sphinx優秀的部分
1、部署簡單,雖然sphinx部署也挺簡單,但是在書寫配置的時候,你會發現,sphinx的配置是要寫好後,重啟sphinx,而Elasticsearch針對某個索引的配置,是可以動態寫入的。
2、調試簡單,sphinx有命令行工具可以調試,而Elasticsearch使用的是http介面進行調試,不需要專門的API類,幾行php代碼就可以寫一個Elasticsearch的API。
3、可視化工具比較多,有收費的,也有免費的,比如kibana head marvel。
4、提供結構化的JSON查詢語句,易讀性強
5、Es可以保留源數據(可選),也就是說,你可以不需要mysql的支持,就可以完成整個搜索過程,即使你不需要這個功能,在調試的時候,還是讓人感到非常便利,不用將查詢結果到資料庫匹配一下。
6、Es可以動態更新全文索引,動態更新單個記錄,而不像sphinx一樣需要重建全部
7、對UTF8的支持是不需要單獨配置的

## 從中文分詞上來說
首先分詞最重要的基本都是詞庫,分詞演算法兩個工具基本都可以使用。
lucene 支持很多分詞工具,比如
word https://github.com/ysc/word
比如ik https://github.com/medcl/elasticsearch-analysis-ik
這兩個工具最近都很活躍,因為Es更新2.0 和 2.1

比較分詞區別(sphinx可能有誤):
sphinx分詞 不太熟悉它的機制,多數情況下使用scws分詞,發送給sphinx,然後設置匹配規則,比如最大匹配(我基本都是基於模糊匹配在用sphinx)

Es的全文索引是基於分詞的,也就是事先分好詞,每個詞對應某些記錄,自動進行TF/IDF的運算,得到一個評分後返回,當然這個評分可以改(sphinx同樣支持修改評分),這種檢索方式肯定更快,但是受到分詞限制,所以我每個字也分詞,然而這樣可能影響分數判斷。

另一方面ES也支持類似sphinx的匹配方式,叫做fuzzy,模糊匹配,一般會一起使用,一個詞不在分詞庫中的時候,就用fuzzy,所以Es在功能上,應該和sphinx不會有太多差別,而且應該要更多。

## 個人方面
在使用shpinx的時候,會查3次,一次完全按照用戶輸入的查(如果用戶沒有輸入空格),一次按照空格分開查或者分詞系統分詞結果查,一次按照單個字來查(前提是前面兩個結果太少)。

在用Es的時候,如果沒有辦法正確分詞,會按照fuzzy + 單字查(可以同時進行),如果有辦法分詞,按照分詞結果 + 單字查(可以同時)

## 後期維護上:
sphinx的配置文件在mysql分表之後,維護起來是比較麻煩的,你可以用php腳本當做配置文件,這樣會好很多。
Es的索引是可以主動發給它去建立的(通過http介面),分表之後,它不關心資料庫狀態和結構。新增欄位可以熱更新。

## 擴展性上:
Es和sphinx都支持分布式索引,擴展性都沒有問題
兩者都支持別名,Es的別名加上動態建立索引,使得更換索引結構或者重建索引後,支持0宕機時間。而sphinx的rotate選項可以動態更新索引(不知道能不能動態創建索引,因為sphinx我在使用的時候,索引都要求寫在配置文件里。
性能方面沒有測試數據。從直觀感受上sphinx要快一些。

『叄』 電腦-Sphinx在windows下安裝使用[支持中文全文檢索]

前一陣子嘗試使用了一下Sphinx,一個能夠被各種語言(PHP/python/Ruby/etc)方便調用的全文檢索系統。網上的資料大多是在linux環境下的安裝使用,當然,作為生產環境很有必要部署在*nix環境下,作為學習測試,還是windows環境比較方便些。

本文旨在提供一種便捷的方式讓Sphinx在windows下安裝配置以支持中文全文檢索,配置部分在linux下通用。

一、關於Sphinx

Sphinx 是一個在GPLv2 下發布的一個全文檢索引擎,商業授權(例如, 嵌入到其他程序中)需要聯系作者(Sphinxsearch.com)以獲得商業授權。

一般而言,Sphinx是一個獨立的搜索引擎,意圖為其他應用提供高速、低空間佔用、高結果相關度的全文搜索功能。Sphinx可以非常容易的與SQL資料庫和腳本語言集成。

當前系統內置MySQL和PostgreSQL 資料庫數據源的支持,也支持從標准輸入讀取特定格式的XML數據。通過修改源代碼,用戶可以自行增加新的數據源(例如:其他類型的DBMS的原生支持)。

搜索API支持PHP、Python、Perl、Rudy和Java,並且也可以用作MySQL存儲引擎。搜索API非常簡單,可以在若干個小時之內移植到新的語言上。

Sphinx特性:

高速的建立索引(在當代CPU上,峰值性能可達到10MB/秒); 高性能的搜索(在2–4GB的文本數據上,平均每次檢索響應時間小於0.1秒); 可處理海量數據(目前已知可以處理超過100GB的文本數據,在單一CPU的系統上可處理100M文檔); 提供了優秀的相關度演算法,基於短語相似度和統計(BM25)的復合Ranking方法; 支持分布式搜索; 提供文件的摘錄生成; 可作為MySQL的存儲引擎提供搜索服務; 支持布爾、短語、詞語相似度等多種檢索模式; 文檔支持多個全文檢索欄位(最大不超過32個); 文檔支持多個額外的`屬性信息(例如:分組信息,時間戳等); 停止詞查詢; 支持單一位元組編碼和UTF-8編碼; 原生的MySQL支持(同時支持MyISAM和InnoDB); 原生的PostgreSQL支持.

中文手冊可以在這里獲得(酷勤網備用下載地址:sphinx_doc_zhcn_0.9.pdf)。

二、Sphinx在windows上的安裝

1.直接在http://www.sphinxsearch.com/downloads.html找到最新的windows版本,我這里下的是Win32 release binaries with MySQL support,下載後解壓在D:sphinx目錄下;

2.在D:sphinx下新建一個data目錄用來存放索引文件,一個log目錄方日誌文件,復制D:sphinxsphinx.conf.in到D:sphinxbinsphinx.conf(注意修改文件名);

3.修改D:sphinxbinsphinx.conf,我這里列出需要修改的幾個:

type= mysql # 數據源,我這里是mysqlsql_host;= localhost # 資料庫伺服器sql_user;= root # 資料庫用戶名sql_pass;=;'' # 資料庫密碼sql_db;;;= test # 資料庫sql_port;= 3306 # 資料庫埠

sql_query_pre;;;= SET NAMES utf8 # 去掉此行前面的注釋,如果你的資料庫是uft8編碼的

index test1{#;放索引的目錄;path;;;= D:/sphinx/data/# 編碼;charset_type;;= utf-8;#; 指定utf-8的編碼表;charset_table=0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F;# 簡單分詞,只支持0和1,如果要搜索中文,請指定為1;ngram_len;;;;= 1# 需要分詞的字元,如果要搜索中文,去掉前面的注釋;ngram_chars;;;= U+3000..U+2FA1F}

# index test1stemmed : test1# {;# path;;;= @CONFDIR@/data/test1stemmed;# morphology;;= stem_en# }# 如果沒有分布式索引,注釋掉下面的內容# index dist1# {;# 'distributed' index type MUST be specified;# type;;;;= distributed

;# local index to be searched;# there can be many local indexes configured;# local;;;;= test1;# local;;;;= test1stemmed

;# remote agent;# multiple remote agents may be specified;# syntax is 'hostname:port:index1,[index2[,...]];# agent;;;;= localhost:3313:remote1;# agent;;;;= localhost:3314:remote2,remote3

;# remote agent connection timeout, milliseconds;# optional, default is 1000 ms, ie. 1 sec;# agent_connect_timeout;= 1000

;# remote agent query timeout, milliseconds;# optional, default is 3000 ms, ie. 3 sec;# agent_query_timeout;;= 3000# }

# 搜索服務需要修改的部分searchd{;# 日誌;log;;;;;= D:/sphinx/log/searchd.log

;# PID file, searchd process ID file name;pid_file;;;= D:/sphinx/log/searchd.pid

# windows下啟動searchd服務一定要注釋掉這個 # seamless_rotate;;= 1}

4.導入測試數據

C:Program FilesMySQLMySQL Server 5.0bin>mysql -uroot test<d:/sphinx/example.sql

5.建立索引

D:sphinxbin>indexer.exe test1

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 『./sphinx.conf』…

indexing index 『test1′…

collected 4 docs, 0.0 MB

sorted 0.0 Mhits, 100.0% done

total 4 docs, 193 bytes

total 0.101 sec, 1916.30 bytes/sec, 39.72 docs/sec

D:sphinxbin>

6.搜索』test』試試

D:sphinxbin>search.exe test

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 『./sphinx.conf』…

index 『test1′: query 『test 『: returned 3 matches of 3 total in 0.000 sec

displaying matches:

1. document=1, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=1

;;;;;group_id=1

;;;;;group_id2=5

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=test one

;;;;;content=this is my test document number one. also checking search within

;phrases.

2. document=2, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=2

;;;;;group_id=1

;;;;;group_id2=6

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=test two

;;;;;content=this is my test document number two

3. document=4, weight=1, group_id=2, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=4

;;;;;group_id=2

;;;;;group_id2=8

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=doc number four

;;;;;content=this is to test groups

words:

1. 『test』: 3 documents, 5 hits

D:sphinxbin>

都所出來了吧。

6.測試中文搜索

修改test資料庫中documents數據表,

UPDATE `test`.`documents` SET `title` = 『測試中文』, `content` = 『this is my test document number two,應該搜的到吧』 WHERE `documents`.`id` = 2;

重建索引:

D:sphinxbin>indexer.exe –all

搜索』中文』試試:

D:sphinxbin>search.exe 中文

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 『./sphinx.conf』…

index 『test1′: query 『中文 『: returned 0 matches of 0 total in 0.000 sec

words:

D:sphinxbin>

貌似沒有搜到,這是因為windows命令行中的編碼是gbk,當然搜不出來。我們可以用程序試試,在D:sphinxapi下新建一個foo.php的文件,注意utf-8編碼

<?php

require 』sphinxapi.php』;

$s = new SphinxClient();

$s->SetServer(』localhost』,3312);

$result = $s->Query(』中文』);

var_mp($result);

?>

啟動Sphinx searchd服務

D:sphinxbin>searchd.exe

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing –console mode on Windows

using config file 『./sphinx.conf』…

creating server socket on 0.0.0.0:3312

accepting connections

執行PHP查詢:

php d:/sphinx/api/foo.php

結果是不是出來?剩下的工作就是去看手冊,慢慢摸索高階的配置。

『肆』 mysql怎麼與sphinx建立索引

安裝sphinx
yum
install
sphinx
libsphinxclient-devel
配置sphinx代替mysql全文索引(/etc/sphinx/sphinx.conf)
source
account_src
{
type
=
mysql
sql_host
=
localhost
sql_user
=
root
sql_pass
=
sql_db
=
test
sql_port
=
3306
sql_query_pre
=
SET
NAMES
utf8
sql_query
=
\
SELECT
*
\
FROM
tb_account
#sql_attr_uint
=
idx_id
sql_field_string
=
name
sql_attr_uint
=
age
}
index
account_idx
{
source
=
account_src
path
=
/var/lib/sphinx/account_src
docinfo
=
extern
charset_type
=
utf-8
}
indexer
{
mem_limit
=
32M
}
searchd
{
listen
=
127.0.0.1:9312
listen
=
9306:mysql41
log
=
/var/log/sphinx/searchd.log
query_log
=
/var/log/sphinx/query.log
read_timeout
=
5
max_children
=
30
pid_file
=
/var/run/sphinx/searchd.pid
max_matches
=
1000
seamless_rotate
=
1
preopen_indexes
=
1
unlink_old
=
1
workers
=
threads
#
for
RT
to
work
binlog_path
=
/var/lib/sphinx
}
創建全量索引
indexer
--config
/etc/sphinx/sphinx.conf
--all
啟動後台搜索服務
searchd
--config
/etc/sphinx/sphinx.conf
可設置crontab定期構建索引
indexer
--config
/etc/sphinx/sphinx.conf
--rotate
account_idx
測試(自帶search工具已不可用,可參照這里),所以需要源碼安裝sphinx的php擴展

『伍』 php windows下怎麼安裝sphinx,安裝後又怎麼使用

1、下載,我這里下的是「Win64 binaries w/MySQL+PgSQL+libstemmer+id64 support」,下載後文件名:sphinx-2.0.6-release-win64-id64-full.zip;
2、將其解壓到D: \ sphinx,並在D:\sphinx下新建目錄data(用來存放索引文件)與log(用來存放日誌文件);
3、將D:\sphinx\sphinx.conf.in復制到D:\sphinx\bin\sphinx.conf.in,並重命名為sphinx.conf;
4、修改 D:\sphinx\bin\sphinx.conf 如下:
4.1、搜索source src1修改{...}中的內容
# 使用的資料庫類型
type = mysql
# 伺服器
sql_host = localhost
# 資料庫登錄名
sql_user = root
# 資料庫登錄密碼
sql_pass = root
# 操作的資料庫名稱
sql_db = test
# 資料庫伺服器埠
sql_port = 3306
# 設置編碼,如果用的是utf-8編碼
sql_query_pre = SET NAMES utf-8
(以上7條前如有#將其刪除)
4.2、搜索index test1修改{...}中的內容
# 放索引的目錄
path = D:/sphinx/data/
# 編碼
charset_type = utf-8
# 指定utf-8編碼表
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
# 簡單分詞,只有0和1,需要搜索中文必須置1
ngram_len = 1
# 需要分詞的字元,搜索中文時必須
ngram_chars = U+3000..U+2FA1F
(以上5條前如有#將其刪除)
5、導入測試數據將D:\sphinx\example.sql中語句執行到test資料庫中,注意:test資料庫創建時需要指定為utf-8格式;
6、打開cmd窗口,進入目錄D:\sphinx\bin;
7、建立索引,執行indexer.exe test1,test1即為sphinx.conf中index test1
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphin

using config file './sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 222 bytes
total 0.019 sec, 11252 bytes/sec, 202.74 docs/sec
total 2 reads, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
成功...
8、搜索'test',執行search.exe test
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2421, group_id=1, date_added=Tue Feb 26 10:25:31 2013
id=1
group_id=1
group_id2=5
date_added=2013-02-26 10:25:31
title=test one
content=this is my test document number one. also checking search within
phrases.
2. document=2, weight=1442, group_id=3, date_added=Tue Feb 26 10:25:31 2013
id=2
group_id=3
group_id2=6
date_added=2013-02-26 10:25:31
title= ????
content=this is my test document number two ???????
3. document=4, weight=1442, group_id=2, date_added=Tue Feb 26 10:25:31 2013
id=4
group_id=2
group_id2=8
date_added=2013-02-26 10:25:31
title=doc number four
content=this is to test groups

words:
1. 'test': 3 documents, 4 hits

index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s
ph: No such file or directory.
最後面的一句error可忽略;
9、搜索中文,首先將資料庫中的內容update含有中文,執行sql語句:
UPDATE documents SET title='中文', content='this is my test document number one. also checking search within phrases.含有中文。' WHERE id=1;
UPDATE documents SET title='中文標題', content='this is my test document number one. also checking search within phrases.含有中文內容。' WHERE id=2;
UPDATE documents SET title='中文標題測試', content='this is my test document number one. also checking search within phrases.含有中文內容。' WHERE id=3;
重新建立索引(執行第7步);
然後執行search.exe 中文
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 349 bytes
total 0.025 sec, 13808 bytes/sec, 158.26 docs/sec
total 2 reads, 0.000 sec, 0.3 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg

D:\sphinx\bin>search.exe 中文
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
index 'test1': query '中文 ': returned 0 matches of 0 total in 0.000 sec

words:

index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s
ph: No such file or directory.
沒有搜索到,因為windows命令行中的中文時GBK編碼格式,所以沒有匹配內容。我們可以使用PHP程序來試試;
10、進入D:\sphinx\api\目錄,可以發現sphinx支持php、java、ruby調用,並提供對應的test例子,這里我們使用php來操作,首先將api復制到D:\www\下並重命名為sphinxapi,因為我本機上apache的web目錄為D:\www,在D:\www\sphinxapi\下新建search.php,內容為:
<?php
require 'sphinxapi.php';
$s = new SphinxClient();
$s->SetServer('localhost', 9312);
$result = $s->Query('中國');
print_r($result);
echo '<br /><br />';
$result = $s->Query('中文');
print_r($result);
?>
然後回到cmd命令行中,開啟sphinx服務,執行searchd.exe(這個必須要執行的)
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your application
and config
WARNING: preopen_indexes=1 has no effect with seamless_rotate=0
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'test1'
precaching index 'test1stemmed'
WARNING: index 'test1stemmed': preload: failed to open D:/sphinx/data/test1stemm
ed.sph: No such file or directory; NOT SERVING
precaching index 'rt'
WARNING: index 'rt': preload: failed to open @CONFDIR@/data/rt.lock: No such fil
e or directory; NOT SERVING
precached 3 indexes in 0.018 sec
成功...
然後在瀏覽器中執行http://localhost/sphinxapi/search.php,列印出來的數組結果可以很清晰的看見搜索的結果比對。。。
11、至此sphinx在windows下的簡單安裝與使用就完成了。

『陸』 php,sphinx 搜索結果分組問題

setFilter 將城市信息 做為碼表存起來。

『柒』 怎麼用php+sphinx+mongodb來打造千萬級搜索

sphinx不能直接支持mongodb的。我們之前是用python來建立sphinx和mongodb之間的數據介面。sphinx索引完成之後,搜索動作時在sphinx自身的索引文件上完成的,不涉及的對資料庫的搜索了。然後php再根據sphinx給出的id去讀mongodb就可以了,怎麼會出現斷開什麼的?
不過python去讀mongodb的速度肯定要比sphinx自己直接讀mysql要慢,有實力的話可以自己用c寫個介面。

『捌』 php中spinx怎麼安裝使用

1. 從http://sphinxsearch.com 下載Sphinx 2.0.1-beta

2. 解壓縮到合適目錄(這里以d:\shpinx為例)

3. 建立配置文件
Sphinx包默認附帶sphinx.conf.in,sphinx-min.conf.in,example.sql例子,我們完全可以從
sphinx-min.conf.in復制出一個sphinx.conf用來測試。

修改sphinx.conf必要項(資料庫作為數據源):mysql資料庫連接項(參照example.sql建立測試數據到資料庫);@CONFDIR@替換成實際目錄,然後手動建立好該目錄及子目錄,這里為

d:\sphinx\data # 索引數據目錄
d:\sphinx\log # 進程文件目錄

4. 安裝Sphinx到Windows服務
searchd.exe --install -c d:\sphinx\sphinx.conf --servicename SphinxSearch
啟動該服務

5. PHP客戶端測試
進入d:\sphinx\api目錄,sphinx提供了php, python , ruby , c等客戶端代碼,如果Php程序員想訪問Sphinx,包含sphinxapi.php就可以了 ,test.php是Sphinx提供的訪問例子。

在測試之前,需要生成索引文件到d:\shpinx\data目錄,進入d:\sphinx\bin執行
indexer.exe -c d:\sphinx\sphinx.conf --all
運行成功後必須重新啟動Sphinx才能生效。重啟後執行test.php
php test.php test

『玖』 php php for循環查詢資料庫效率低,該如何優化mysql mysql

那就用sphinx 技術,目前這個是最好的,沒有之一。
下面是我網路弄過來的,怎麼使用還得你自己看白皮書了。
Sphinx的主要特性包括:
高速索引 (在新款CPU上,近10 MB/秒);
高速搜索 (2-4G的文本量中平均查詢速度不到0.1秒);
高可用性 (單CPU上最大可支持100 GB的文本,100M文檔);
提供良好的相關性排名
支持分布式搜索;
提供文檔摘要生成;
提供從MySQL內部的插件式存儲引擎上搜索
支持布爾,短語, 和近義詞查詢;
支持每個文檔多個全文檢索域(默認最大32個);
支持每個文檔多屬性;
支持斷詞;
支持單位元組編碼與UTF-8編碼。[1]

『拾』 mysql怎麼與sphinx建立索引

安裝sphinx
yum install sphinx libsphinxclient-devel

配置sphinx代替mysql全文索引(/etc/sphinx/sphinx.conf)

source account_src
{
type = mysql

sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = 3306
sql_query_pre = SET NAMES utf8

sql_query = \
SELECT * \
FROM tb_account

#sql_attr_uint = idx_id
sql_field_string = name
sql_attr_uint = age
}

index account_idx
{
source = account_src
path = /var/lib/sphinx/account_src
docinfo = extern
charset_type = utf-8
}

indexer
{
mem_limit = 32M
}

searchd
{
listen = 127.0.0.1:9312
listen = 9306:mysql41
log = /var/log/sphinx/searchd.log
query_log = /var/log/sphinx/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinx/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinx
}

創建全量索引
indexer --config /etc/sphinx/sphinx.conf --all

啟動後台搜索服務
searchd --config /etc/sphinx/sphinx.conf

可設置crontab定期構建索引
indexer --config /etc/sphinx/sphinx.conf --rotate account_idx

測試(自帶search工具已不可用,可參照這里),所以需要源碼安裝sphinx的php擴展

閱讀全文

與sphinxphpmysql相關的資料

熱點內容
新的app有什麼 瀏覽:534
程序員可以當主任嗎 瀏覽:151
linux30下載 瀏覽:596
活塞式製冷壓縮機的分類有哪些 瀏覽:719
農業app哪個最出名 瀏覽:262
安卓打游戲都是用什麼錄屏 瀏覽:930
107區的伺服器是什麼 瀏覽:658
非對稱加密的加密簽名的過程 瀏覽:443
mysqlinsert命令 瀏覽:198
電腦盤加密碼打開後怎麼鎖起來 瀏覽:174
安卓系統是什麼代碼編譯的 瀏覽:295
解壓單車模擬器游戲 瀏覽:501
應用程序員需要懂很多硬體知識嗎 瀏覽:396
我的世界伺服器110地址大全 瀏覽:624
怎麼qq相冊加密自己也不能看 瀏覽:22
linuxc語言串口數據 瀏覽:857
mac下編寫python 瀏覽:973
厚襯衣程序員 瀏覽:743
一年級編程精彩內容 瀏覽:578
cc2540編程 瀏覽:794