sphinx是一個高效的搜尋引擎,分詞搜尋的速度比較快,索引建立儲存在硬碟文件,不會幹擾資料庫,有自己內建的一套資料庫.希望能幫助大家。
sphinx是一個高效的搜尋引擎,分詞搜尋的速度比較快,索引建立儲存在硬碟文件,不會幹擾資料庫,有自己內建的一套資料庫
如果沒有安裝aptitude ,需要先安裝aptitude 因為因為用apt get install 安裝下面指令會出現問題.<br> sudo apt-get install aptitude
<br>sudo aptitude install sphinx3 sphinx3-doc sphinxsearch sphinx-common -y
<br>###1######2##########
<br>###cd /etc/sphinxsearch/######cp sphinx.conf. sample sphinx.conf################
修改設定檔如下<br>
<br> 1 2 ##3 4567891011 12131415161718192021222324252627282930313233343536373839#404142434445#46 #47484950#51 |
source src1 #{type = mysqlsql_host = localhostsql_user = rootsql_pass = magicmoma#sql_db = coupon_20160901 sql_port = 3306 # optional, default is 3306sql_query = SELECT couponid,title,description FROM app_coupon_api 欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引列包含主鍵,分詞索引欄位包含主鍵,分詞索引欄位包含主鍵,分詞索引位包含主鍵碼 #} index test1 { source = src1 path = /var/lib/sphinxsearch/ data/test1 #索引存放目錄 docinfo = extern mlock = 0 morphology = none min_word_len = 1 charset_type = utf-8 min_prefix_len = 0 min_infix_len = 0 ngram_len = 1 #html_strip = 0 } #indexer { mem_limit = 2048M }<br> ##searchd#{ listen = 9312listen = 9306:mysql41log = /var/log/sphinxsearch/searchd.logquery_log = /var/log /sphinxsearch/query.logread_timeout = 5client_timeout = 300max_children = 30pid_file = /var/run/sphinxsearch/searchd. pidmax_matches = 1000seamless_rotate = 1preopen_indexes = 1##unlink_old = 1 mva_updates_pool = 1M max_packet_size = 8M max_filters = 256 max_filter_values = 4096 ##max_batch_queries = 32workers = threads # for RT to work##} |
#<br> 1 ##23 4567#8910111213 | #public function testSphinx(){$s = new \SphinxClient;$s->setServer("localhost", 9312);$s->SetArrayResult (true ); $s->setMatchMode(SPH_MATCH_ANY);$s->setMaxQueryTime(3);$result = $s->query("test"); $result = $result['matches'];$result = array_column($result,'id');$list = M('CouponApi')-> ;field('couponid,title,description')->where(array('couponid'=>array('in',$result)))->select();dump( $list);} |
$ s->SetLimits(0, 1000, 1000);),搜尋速度相當快,索引80w條資料的title和description兩個欄位耗時不到10s,該搜尋引擎支援增量索引,多種模式的搜索,網上的資料也非常多
以上是php中如何使用sphinx搜尋引擎的詳細內容。更多資訊請關注PHP中文網其他相關文章!