本文介绍了一些主要和重大变更,但你可以查看 完整更改日志 这里。
新功能:嵌套字段支持
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
:是否启用错字容忍度功能。默认为 true。disableOnAttributes
:在特定文档属性上禁用错字容忍度。默认情况下,所有属性都启用错字容忍度。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 使用量的新的实例选项的支持。
就这样了,朋友们!记得查看 更改日志 获取完整的发行说明,我们下个月再见!