去重属性是一个字段,它阻止 Meilisearch 返回一组相似的文档。常用于电子商务数据集中,其中许多文档是相同商品的变体。
distinctAttribute
索引设置,或在搜索时使用 distinct
搜索参数。distinctAttribute
是一个索引设置,它配置 Meilisearch 应用于该索引中所有搜索和分面检索的默认去重属性。
distinctAttribute
。尝试将多个字段设置为 distinctAttribute
将返回错误。internal_id
返回第一个结果。lee leather jacket
将返回所有三个文档。这可能不是期望的,因为显示几乎相同的项目变体会使结果显得杂乱。 在这种情况下,您可能只想返回一个带有对应于此 Lee 牛仔皮夹克的 product_id
的文档。为此,您可以将 product_id
设置为 distinctAttribute
。distinctAttribute
设置为 product_id
,搜索请求永远不会返回具有相同 product_id
的多个文档。 如上所示设置去重属性后,查询 lee leather jacket
将只返回找到的第一个文档。响应将如下所示:distinct
是一个您可以添加到任何搜索查询的搜索参数。它允许您根据上下文选择性地使用去重属性。distinct
优先于 distinctAttribute
。 要将属性与 distinct
一起使用,请先将其添加到 filterableAttributes
列表中:distinct
,指定一个已配置的属性