時(shí)間:2023-04-02 07:46:02 | 來(lái)源:電子商務(wù)
時(shí)間:2023-04-02 07:46:02 來(lái)源:電子商務(wù)
https://github.com/meilisearch/MeiliSearch在介紹 MeiliSearch 的功能之前,我想先聊下我是怎么找到它并喜歡上它的。
curl -L https://install.meilisearch.com | sh./meilisearch
這個(gè)安裝夠不夠傻瓜 啟動(dòng)成功如下圖:http://127.0.0.1:7700/
就可以看到 MeiliSearch 提供的 Web 搜索頁(yè)面。我提前寫(xiě)入了一些數(shù)據(jù),用來(lái)演示搜索:# 要求 Python3.6+pip3/pip install meilisearch
用 Python 實(shí)現(xiàn)連接、寫(xiě)入、查詢(xún)、刪除等基本操作:import meilisearchclient = meilisearch.Client('http://127.0.0.1:7700', 'masterKey') # masterKey 是密碼# index 相當(dāng)于數(shù)據(jù)庫(kù)的表index = client.index('books')# 準(zhǔn)備寫(xiě)入搜索的數(shù)據(jù)documents = [ { 'book_id': 123, 'title': 'Pride and Prejudice' }, { 'book_id': 456, 'title': 'Le Petit Prince' }, { 'book_id': 1, 'title': 'Alice In Wonderland' }, { 'book_id': 1344, 'title': 'The Hobbit' }, { 'book_id': 4, 'title': 'Harry Potter and the Half-Blood Prince' }, { 'book_id': 42, 'title': 'The Hitchhiker/'s Guide to the Galaxy' }]# 刪:清空指定 indexindex.delete_all_documents()# 寫(xiě):result = index.add_documents(documents) # 該引擎會(huì)根據(jù)寫(xiě)入數(shù)據(jù) ID 做替換或者新增的操作# 寫(xiě)入后并不代表搜索引擎處理完成,可以查看返回 updateId 的狀態(tài)index.get_update_status(result.get('updateId'))# enqueued, processed or failed 三種狀態(tài)(processed 代表完成)# 查:index.search('harry pottre')# 結(jié)果:# 包含豐富的字段"""{ // 命中的結(jié)果 "hits" => [{ "book_id" => 4, "title" => "Harry Potter and the Half-Blood Prince" }], // 頁(yè) "offset" => 0, // 每頁(yè)條數(shù) "limit" => 20, // 處理耗時(shí) "processingTimeMs" => 1, // 查詢(xún)的內(nèi)容 "query" => "harry pottre"}"""
至此已經(jīng)實(shí)現(xiàn)了搜索的最基本的功能,但探索不止于此。# 停用詞client.index('movies').update_settings({ 'stopWords': [ 'the', 'a', 'an' ],})# 排序規(guī)則client.index('movies').update_ranking_rules([ "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", "asc(publish_time)", "desc(watch)"])# 查看 stop wordsclient.index('movies').get_stop_words()# 重置設(shè)置# index.reset_settings()# 除了搜索其它操作都是異步,會(huì)直接返回一個(gè) updateId 需要通過(guò) ID 查詢(xún)處理狀態(tài)# wait_for_pending_update 可阻塞等待處理結(jié)果
這些設(shè)置可以有效的提高搜索效果,比如使用停用詞之前,搜索“開(kāi)源的書(shū)籍”命中不了“開(kāi)源書(shū)籍”,加了停用詞即可命中,因?yàn)槠ヅ鋾r(shí)忽略了輸入內(nèi)容包含的停用詞(無(wú)用詞)。cat << EOF > /etc/systemd/system/meilisearch.service[Unit]Description=MeiliSearchAfter=systemd-user-sessions.service[Service]Type=simpleExecStart=/usr/bin/meilisearch --http-addr 127.0.0.1:7700 --env production --master-key xxxxxx[Install]WantedBy=default.targetEOF# Set the service meilisearchsystemctl enable meilisearch# Start the meilisearch servicesystemctl start meilisearch# Verify that the service is actually runningsystemctl status meilisearch
但部署正式環(huán)境,需要注意以下幾點(diǎn):curl 地址
查看服務(wù)狀態(tài)優(yōu)秀的開(kāi)源項(xiàng)目像散落在海邊的貝殼,需要發(fā)現(xiàn)它的人。
HelloGitHub 就是拾貝者,找開(kāi)源項(xiàng)目來(lái) HelloGitHub 就對(duì)了!
關(guān)鍵詞:索引
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。