我最近爲我的MySQL數據庫安裝了sphinx,並且配置了配置文件&我在運行search.exe時得到了正確的結果,但是當我使用PHP API(以及CodeIgniter的包裝器)。我仍然是零結果。現在我很確定我的php代碼是正確的,因爲它是基本的(獲取密鑰,運行mysql查詢並返回結果)。什麼原因可能導致這樣的問題?這裏是sphinx配置文件的searchd部分,我需要修改任何東西嗎? :Sphinx的search.exe正確返回結果,但PHP API沒有任何返回
searchd
{
# listen = 9312
listen = 9306:mysql41
port = 3312
log = C:/sphinx/log/searchd.log
query_log = C:/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = C:/sphinx/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:/sphinx/data
}
這裏是我的search.php獅身人面像的查詢:
$search_string=$this->input->post('q');
$this->load->library('Sphinxclient');
$this->sphinxclient->setMatchMode(SPH_MATCH_ANY);
$this->sphinxclient->SetArrayResult(TRUE);
$users_ids=$this->sphinxclient->Query('users_info',$search_string);
現在我不知道該API或獅身人面像如何找到mysql目錄,並連接到它,但我讀了獅身人面像文檔以及基本的api函數部分,它表示函數SetServer具有默認值「localhost」和端口「9312」。這可能是問題,因爲在我的配置文件中,我有一個不同的端口,我已經評論了9312聽力?
這裏是我對users_info源碼和索引的定義(雖然我懷疑這是因爲search.exe能夠得到結果的問題)。
source users_info
{
type = mysql
sql_host = localhost
sql_user = admin
sql_pass = admin
sql_db = users
sql_sock = /var/run/mysqld/mysqld.sock
sql_port = 3306
sql_query = \
SELECT id, fullname,username FROM users_info;
sql_query_info = SELECT * FROM users WHERE id=$id
}
和索引:
index users_info
{
source = users_info
path = C:/sphinx/data/users_info
docinfo = extern
charset_type = utf-8
}
此外,還有一兩件事,在API中,我翻在API中的查詢函數的參數,我有固定的,但沒有解決問題。
任何想法?
您是否運行了索引器?另外,運行查詢後是否有任何錯誤?你可以通過運行'$ this-> sphinxclient-> getLastError()'並回顯結果來找到它。 –
問題原來是,在我的表單輸入字段中,我沒有指定方法,所以沒有得到搜索查詢輸入。一切都在工作。只是一個白癡錯誤。非常感謝 – Pacemaker