v0.27 版本的新功能
本月发布的版本带来了对嵌套字段、自定义拼写容错以及新的搜索参数的支持。

本文着眼于一些主要和重大更改,但您可以在此处查看完整更新日志。
新功能:嵌套字段支持
Meilisearch 现在提供对嵌套文档字段的全面支持,允许您使用点表示法访问这些字段。
让我们举个例子。如果您有一个书店索引,您可能希望使搜索结果可按作者的姓氏过滤,但不能按他们的名字过滤
curl -X POST 'http://localhost: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://localhost: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://localhost: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://localhost: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 使用情况的新实例选项的支持。
各位,就这些!请记住查看更新日志以获取完整的发行说明,下个月见!