可显示和可搜索属性定义了 Meilisearch 在成功查询后返回的数据以及 Meilisearch 在搜索时考虑的字段。了解如何配置它们可以帮助提高应用程序的性能。
displayedAttributes
:字段显示在文档中的属性searchableAttributes
:其值用于匹配查询词的属性displayedAttributes
列表中的字段将显示在每个匹配的文档中。 搜索时返回的文档仅包含可显示字段。如果字段属性不在可显示属性列表中,则该字段不会添加到返回的文档中。 默认情况下,所有字段属性都设置为可显示。title
、overview
、release_date
和 genres
字段。
searchableAttributes
列表searchableAttributes
列表有两个目的:searchableAttributes
列表有两种可能的模式。
searchableAttributes
列表中。这意味着初始顺序将基于第一个索引文档中的属性顺序,后续文档中发现的每个新属性将添加到此列表的末尾。 这种默认行为由 searchableAttributes
值为 ["*"]
表示。要验证 searchableAttributes
列表的当前值,请使用获取可搜索属性端点。 如果您想将可搜索属性列表恢复到此默认行为,将 searchableAttributes
设置为空数组 []
或使用重置可搜索属性端点。searchableAttributes
列表后,除非重置设置,否则后续新属性将不再自动添加。searchableAttributes
将更改 JSON 响应中文档字段的显示顺序。此行为不一致,将在未来的版本中修复。id
、overview
、genres
、title
、release_date
。这些字段都包含有用的信息。但是,有些字段比其他字段更有用。为了使 id
和 release_date
字段不可搜索,并按重要性重新排序剩余字段,您可以按以下方式更新可搜索属性列表。
searchableAttributes
列表中的所有属性。使用attributesToSearchOn
搜索参数可将特定查询限制为您索引的 searchableAttributes
子集。
displayedAttributes
列表和 searchableAttributes
列表中都缺失,它仍然存储在数据库中,并且可以随时添加到其中一个或两个列表中。