時間:2023-03-16 23:42:01 | 來源:電子商務(wù)
時間:2023-03-16 23:42:01 來源:電子商務(wù)
傻瓜一詞借鑒自傻瓜相機(jī),又稱輕便相機(jī)、全自動相機(jī),通常指容易操作針對一般人而設(shè)計的小型全自動相機(jī)。在 HelloGitHub 找到有趣、入門級的開源項目,大家好我是鹵蛋。說到開源搜索引擎第一個想到的應(yīng)該是鼎鼎大名的 ElasticSearch,但 ES 對于個人項目有些重。
https://github.com/meilisearch/MeiliSearch在介紹 MeiliSearch 的功能之前,我想先聊下我是怎么找到它并喜歡上它的。
curl -L https://install.meilisearch.com | sh./meilisearch
這個安裝夠不夠傻瓜 啟動成功如下圖:http://127.0.0.1:7700/
就可以看到 MeiliSearch 提供的 Web 搜索頁面。我提前寫入了一些數(shù)據(jù),用來演示搜索:# 要求 Python3.6+pip3/pip install meilisearch
用 Python 實現(xiàn)連接、寫入、查詢、刪除等基本操作:import meilisearchclient = meilisearch.Client('http://127.0.0.1:7700', 'masterKey') # masterKey 是密碼# index 相當(dāng)于數(shù)據(jù)庫的表index = client.index('books')# 準(zhǔn)備寫入搜索的數(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()# 寫:result = index.add_documents(documents) # 該引擎會根據(jù)寫入數(shù)據(jù) ID 做替換或者新增的操作# 寫入后并不代表搜索引擎處理完成,可以查看返回 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" }], // 頁 "offset" => 0, // 每頁條數(shù) "limit" => 20, // 處理耗時 "processingTimeMs" => 1, // 查詢的內(nèi)容 "query" => "harry pottre"}"""
至此已經(jīng)實現(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()# 除了搜索其它操作都是異步,會直接返回一個 updateId 需要通過 ID 查詢處理狀態(tài)# wait_for_pending_update 可阻塞等待處理結(jié)果
這些設(shè)置可以有效的提高搜索效果,比如使用停用詞之前,搜索“開源的書籍”命中不了“開源書籍”,加了停用詞即可命中,因為匹配時忽略了輸入內(nèi)容包含的停用詞(無用詞)。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)境,需要注意以下幾點:curl 地址
查看服務(wù)狀態(tài)優(yōu)秀的開源項目像散落在海邊的貝殼,需要發(fā)現(xiàn)它的人。
HelloGitHub 就是拾貝者,找開源項目來 HelloGitHub 就對了!
關(guān)鍵詞:實現(xiàn),功能,索引,傻瓜
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。