Algolia 不在或不等于

Algolia NOT IN or DOES NOT EQUAL

是否可以使用 'NOT IN' 语法。例如:

  {"Persons" :[{"Name":"Matthew"},{"Name":"John"}]}

Select * 来自 Name!=John

的人

基本上 select 所有没有 John in Persons 的记录。

首先要注意:您应该始终将 Algolia 与数据库结合使用,搜索引擎在您的数据库引擎应该处理的某些操作上会做得很差。


使用 Algolia facets exclusion,绝对可行:

Negations are supported via the - operator, prefixing the facet value.
For example: encodeURIComponent('["category:Book","category:-Movie","author:John Doe"]')

摘自 facetFilters

的文档

对于您的示例,假设 "Name" 是 attributesForFaceting 的一部分,您想要执行的查询很简单:

index.search('query', {
  facetFilters: 'Name:-John'
})

如果您正在使用 algoliasearch-helper-js, the method to use is addExcludeRefinement


最后,值得注意的是,如果您的属性是数字,则应改用 numericFilters