v0.27 版本的新功能
本月發布的版本支援巢狀欄位、錯字容忍度自訂以及新的搜尋參數。

本文將探討一些主要和重大變更,但您可以在此處查看完整變更日誌。
新功能:巢狀欄位支援
Meilisearch 現在完整支援巢狀文件欄位,允許您使用點表示法來存取這些欄位。
讓我們舉個例子。如果您有一個書店索引,您可能希望讓搜尋結果可依作者的姓氏篩選,但不能依其名字篩選
curl -X POST 'http://127.0.0.1:7700/indexes/books/settings/filterable-attributes' -H 'Content-Type: application/json' --data-binary '[ "author.surname" ]'
您可以在 Meilisearch 中使用屬性的任何地方使用點表示法來存取物件屬性。例如,您可以存取索引設定,例如可排序的屬性和可搜尋的屬性,或搜尋參數,例如 attributesToHighlight
。
新功能:自訂錯字容忍度
Meilisearch 具有錯字容忍度!這表示即使您的搜尋包含錯字或拼寫錯誤,我們的引擎也能理解。在 v0.27 中,您可以使用新的更新錯字容忍度端點或現有的更新設定端點,自訂索引的錯字容忍度設定
錯字容忍度的新 API 端點接受具有以下屬性的 typoTolerance
物件
enabled
:是否啟用錯字容忍度功能。預設為 truedisableOnAttributes
:在特定的文件屬性上停用錯字容忍度。預設會在所有屬性上啟用錯字容忍度。disableOnWords
:在搜尋期間給定的一組查詢字詞上停用錯字容忍度。預設情況下,錯字容忍度不會忽略任何字詞。minWordSizeForTypos
:Meilisearch 只接受超過特定大小的字詞中的錯字oneTypo
:自訂接受一個錯字的最小字詞大小。預設為 5 個字元。twoTypos
:自訂接受兩個錯字的最小字詞大小。預設為 9 個字元。
假設您有一個包含許多角色名稱的 movie
索引。您可能希望 Meilisearch 永遠不要在某些字詞中尋找錯字,但對其他所有字詞更寬容
curl --location --request POST 'http://127.0.0.1:7700/indexes/children-movies/settings/typo-tolerance' --header 'Authorization: Bearer <API_KEY>' --header 'Content-Type: application/json' --data-raw '{ "enabled": true, "minWordLengthForTypo": { "oneTypo": 3, "twoTypos": 7 }, "disableOnWords": ["Shrek"], "disableOnAttributes": [] }'
您可以在此處閱讀有關錯字容忍度的詳細資訊。
新功能:改良的醒目提示和裁剪搜尋參數
此版本帶來三個新的搜尋參數:highlightPreTag
、highlightPostTag
和 cropMarker
。前兩個可讓您進一步自訂醒目提示的搜尋字詞外觀,而最後一個應與 attributesToCrop
一起使用。
當使用 attributesToHighlight
時,Meilisearch 預設會將相符的字詞包含在 <em>
和字串中。您現在可以使用 highlightPreTag
和 highlightPostTag
將這些值設定為包含任何字串。顧名思義,highlightPreTag
指定醒目提示的查詢字詞之前的標籤,而 highlightPostTag
指定醒目提示的查詢字詞之後的標籤。
同樣地,當使用 attributesToCrop
時,您現在可以將預設的 "…"
cropMarker
變更為任何字串,以標記裁剪邊界。
當設計允許使用者搜尋電影資料庫的應用程式時,您可能會想要變更 cropMarker
和醒目提示標籤以符合您的設計
curl --location --request POST '<http://127.0.0.1:7700/indexes/movies/search>' \ --header 'Authorization: Bearer <API_KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "q":"shifu", "attributesToCrop":["overview"], "attributesToHighlight":["overview"], "cropLength":10, "highlightPreTag":"<span class=’highlight’>", "highlightPostTag":"</span>", "cropMarker":"[…]" }'
使用上述查詢,搜尋字詞 shifu
會包含在標籤內,而裁剪的文字則以 […]
標記
{ "id": "50393", "title": "Kung Fu Panda Holiday", "overview": "The Winter Feast is Po's favorite holiday. Every year he and his father hang decorations, cook together, and serve noodle soup to the villagers. But this year Shifu informs Po that as Dragon Warrior, it is his duty to host the formal Winter Feast at the Jade Palace. Po is caught between his obligations as the Dragon Warrior and his family traditions: between Shifu and Mr. Ping.", "_formatted": { "id": "50393", "title": "Kung Fu Panda Holiday", **"overview": "[…]the villagers. But this year <span class=’highlight’>Shifu</span> informs Po that as[…]"** } }
如需詳細資訊,請查看我們的搜尋參數指南。
重大變更:`cropLength` 行為
cropLength
搜尋參數現在以字詞而非字元數指定。
讓我們舉個範例查詢
curl --location --request POST '<http://127.0.0.1:7700/indexes/movies/search>' \ --header 'Authorization: Bearer <API_KEY>' \ --header 'Content-Type: application/json' \ --data-raw '{ "q":"shifu", "attributesToCrop":["overview"], "cropLength":10 }'
Meilisearch v0.27 會傳回
{ "id": "50393", "title": "Kung Fu Panda Holiday", "overview": "The Winter Feast is Po's favorite holiday. Every year he and his father hang decorations, cook together, and serve noodle soup to the villagers. But this year Shifu informs Po that as Dragon Warrior, it is his duty to host the formal Winter Feast at the Jade Palace. Po is caught between his obligations as the Dragon Warrior and his family traditions: between Shifu and Mr. Ping.", "_formatted": { "id": "50393", "title": "Kung Fu Panda Holiday", **"overview": "…the villagers. But this year Shifu informs Po that as…",** } }
重大變更:改良的 Docker 工作流程
Docker 現在從不同的工作目錄開始:/meili_data
。這簡化了您可能想要將快照和傾印與 Docker 一起使用時的情況。
用法大致相同,但請勿忘記更新資料路徑
docker run -it --rm \ -p 7700:7700 \ -v $(pwd)/meili_data:/meili_data \ getmeili/meilisearch:latest
透過此變更,傾印和快照功能應該可以立即與 Docker 搭配運作。它會將所有 Meilisearch 資料掛載到 meili_data 目錄中,而不是掛載單獨的磁碟區。
此變更的另一個結果是,meilisearch
二進位檔案已移至新的位置。當使用執行個體選項設定 Meilisearch 時,您現在必須使用 meilisearch
、/meilisearch
或 /bin/meilisearch
而不是 ./meilisearch。不過,我們建議使用 meilisearch
。
更新後的命令為
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest **meilisearch** --master-key="foobar"
其他變更
- 字詞的第一個字母中的錯字會算作兩個錯字。這縮減了錯字容忍度的搜尋空間,進而縮短搜尋回應時間
- Meilisearch 現在具有每個搜尋傳回 1000 個文件的非自訂限制,以保護資料庫免於惡意抓取。
- 我們新增了兩個新的執行個體選項,可讓您更精確地控制索引期間的機器資源使用情況(--max-indexing-memory 和 —-max-indexing-threads)。
- 我們現在支援日語。
- 將新文件新增至非空白索引的速度已提升。
貢獻者
非常感謝所有貢獻者!沒有您的支持,我們無法走到這一步。本月,我們要特別感謝 @miiton、@djKooks、@mosuka 加入日語支援,感謝 @2shiori17 加入對索引期間 RAM 和 CPU 使用情況的新執行個體選項的支援。
各位,就這樣!記得查看變更日誌以了解完整的版本資訊,下個月見!