程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> sphinx在windows下的簡單安裝與使用,sphinxwindows安裝

sphinx在windows下的簡單安裝與使用,sphinxwindows安裝

編輯:MySQL綜合教程

sphinx在windows下的簡單安裝與使用,sphinxwindows安裝


1、下載地址 http://sphinxsearch.com/downloads/release/,我這裡下的是“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下的簡單安裝與使用就完成了。。。

在windows下安裝好sphinx 怎使用php查詢?查詢結果裡數組內容是什?

要配置sphinx.conf文件,把SQL語句放到那裡面,生成相應的索引,在PHP代碼裡面傳值到裡面就會出來查詢出來的結果!
 

WAMP環境下安裝sphinx的步驟,高人指點,越詳細越好

在windows下sphinx和coreseek中文檢索引擎配置
wenku.baidu.com/...3.html
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved