亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

Sphinx在windows下安裝使用[支持中文全文檢索]

瀏覽:76日期:2023-05-22 09:41:30

前一陣子嘗試使用了一下Sphinx,一個能夠被各種語言(PHP/Python/Ruby/etc)方便調(diào)用的全文檢索系統(tǒng)。網(wǎng)上的資料大多是在linux環(huán)境下的安裝使用,當(dāng)然,作為生產(chǎn)環(huán)境很有必要部署在*nix環(huán)境下,作為學(xué)習(xí)測試,還是windows環(huán)境比較方便些。

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

一、關(guān)于Sphinx

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

一般而言,Sphinx是一個獨立的搜索引擎,意圖為其他應(yīng)用提供高速、低空間占用、高結(jié)果相關(guān)度的全文搜索功能。Sphinx可以非常容易的與SQL數(shù)據(jù)庫和腳本語言集成。

當(dāng)前系統(tǒng)內(nèi)置MySQL和PostgreSQL 數(shù)據(jù)庫數(shù)據(jù)源的支持,也支持從標(biāo)準(zhǔn)輸入讀取特定格式的XML數(shù)據(jù)。通過修改源代碼,用戶可以自行增加新的數(shù)據(jù)源(例如:其他類型的DBMS的原生支持)。

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

Sphinx特性:

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

中文手冊可以在這里獲得(酷勤網(wǎng)備用下載地址: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目錄方日志文件,復(fù)制D:sphinxsphinx.conf.in到D:sphinxbinsphinx.conf(注意修改文件名);

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

type= mysql # 數(shù)據(jù)源,我這里是mysqlsql_host;= localhost # 數(shù)據(jù)庫服務(wù)器sql_user;= root # 數(shù)據(jù)庫用戶名sql_pass;=;'' # 數(shù)據(jù)庫密碼sql_db;;;= test # 數(shù)據(jù)庫sql_port;= 3306 # 數(shù)據(jù)庫端口sql_query_pre;;;= SET NAMES utf8 # 去掉此行前面的注釋,如果你的數(shù)據(jù)庫是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# }# 如果沒有分布式索引,注釋掉下面的內(nèi)容# 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# }# 搜索服務(wù)需要修改的部分searchd{;# 日志;log;;;;;= D:/sphinx/log/searchd.log;# PID file, searchd process ID file name;pid_file;;;= D:/sphinx/log/searchd.pid # windows下啟動searchd服務(wù)一定要注釋掉這個 # seamless_rotate;;= 1}

4.導(dǎo)入測試數(shù)據(jù)

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

5.建立索引

D:sphinxbin>indexer.exe test1Sphinx 0.9.8-release (r1533)Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…indexing index ‘test1′…collected 4 docs, 0.0 MBsorted 0.0 Mhits, 100.0% donetotal 4 docs, 193 bytestotal 0.101 sec, 1916.30 bytes/sec, 39.72 docs/sec

D:sphinxbin>

6.搜索’test’試試

D:sphinxbin>search.exe testSphinx 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 two3. 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 hitsD:sphinxbin>

都所出來了吧。

6.測試中文搜索

修改test數(shù)據(jù)庫中documents數(shù)據(jù)表,

UPDATE `test`.`documents` SET `title` = ‘測試中文’, `content` = ‘this is my test document number two,應(yīng)該搜的到吧’ 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āng)然搜不出來。我們可以用程序試試,在D:sphinxapi下新建一個foo.php的文件,注意utf-8編碼

<?phprequire ’sphinxapi.php’;$s = new SphinxClient();$s->SetServer(’localhost’,3312);$result = $s->Query(’中文’);var_dump($result);?>

啟動Sphinx searchd服務(wù)

D:sphinxbin>searchd.exeSphinx 0.9.8-release (r1533)Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing –console mode on Windowsusing config file ‘./sphinx.conf’…creating server socket on 0.0.0.0:3312accepting connections

執(zhí)行PHP查詢:

php d:/sphinx/api/foo.php

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

標(biāo)簽: Windows系統(tǒng)
相關(guān)文章:
主站蜘蛛池模板: xvideos亚洲网站入口 | 国产日产久久 | 韩国黄色一级视频 | 欧美日韩国产不卡在线观看 | 国产真实伦在线观看 | 成人精品视频一区二区三区尤物 | 国产精品高清视亚洲精品 | 国产精品免费拍拍1000部 | 国产特级全黄一级毛片不卡 | 日韩美一区二区三区 | 欧美曰韩一区二区三区 | 中文字幕亚洲不卡在线亚瑟 | 免费人成黄页在线观看69 | 国产资源在线看 | 国产秒拍福利视频露脸 | 91短视频免费在线观看 | 一级全免费视频播放 | 手机在线看黄色 | 久久国产精品1区2区3区网页 | 国产精品亚洲精品 | 欧美亚洲中日韩中文字幕在线 | 污视频在线网站 | 欧美日本在线播放 | 国产精品一区二区欧美视频 | 亚洲a级 | 91精品国产综合久久精品 | 成人久久精品 | 97精品国产高清自在线看超 | 久久久国产精品网站 | 一区二区三区四区在线播放 | 米奇精品一区二区三区 | 久久综合伊人 | 自拍偷拍欧美亚洲 | 免费特黄一级欧美大片 | 91视频入口| 97精品国产 | 亚洲精品一区91 | 国产一区二区三区日韩欧美 | 亚洲 欧美 自拍 另类 欧美 | 色亚洲视频 | 精品在线观看免费 |