在本指南中,您将了解如何在假设的电影数据库中配置和使用 Meilisearch 过滤器。
movie_ratings 的电影集合,其中包含以下字段:
filterableAttributes 列表
filterableAttributes 需要 Meilisearch 重新索引所有数据,这将花费与数据集大小和复杂性成比例的时间。
filterableAttributes 为空。如果没有首先明确将属性添加到 filterableAttributes 列表,过滤器将无法工作。filterfilterableAttributes 索引设置 后,您可以使用 filter 微调搜索结果。 filter 是一个搜索参数,您可以在搜索时使用。 filter 接受使用 filterableAttributes 列表中存在的任何属性构建的过滤器表达式。 以下代码示例返回 1995 年 3 月 18 日之后发布的 Avengers 电影:Tim Burton 或 Christopher Nolan 执导的 Batman 电影
Tim Burton 执导并在 1995 年之后发布的电影,或者由 Christopher Nolan 执导的任何电影,而不对其发布日期施加限制。发生这种情况是因为 AND 优先于 OR。 如果您只想要近期由 Tim Burton 执导的 Planet of the Apes 电影,您可以使用此过滤器:SF 和 San Francisco 设置为同义词,则通过 SF 和 San Francisco 过滤将显示不同的结果。