您如何过滤 Algolia 结果并忽略特定的 objectID
How do you filter Algolia Results and omit a specific objectID
我正在尝试过滤 algolia 结果,并希望使用产品名称在我们的数据库中查找类似产品。我宁愿忽略当前产品,因此如果没有找到结果,将使用 removeWordsIfNoResults
选项。
我正在使用 Ruby api。
这基本上就是我正在尝试的方法,但它不起作用。是否可以过滤掉特定的objectID?
Product.raw_search("Men's Bridge & Burn Camden Steel Blue",
{ :hitsPerPage => 10,
:page => 0,
:attributesToRetrieve => "objectID",
:filters => "objectID != '65411'",
:removeWordsIfNoResults => 'lastWords'
}
)
objectID
是 Algolia 中的一个特定属性,它始终是一个字符串值,不能添加到 attributesForFaceting
中。
但是,如果您使用数据库中的 ID 填充它,则可以使用相同的值索引另一个属性(比方说 id
)。
数值
作为数值,您可以使用 Algolia 直接对其进行过滤。但是,由于您只会使用 !=
运算符,我建议您在 numericAttributesToIndex
列表中使用 equalOnly
修饰符声明它:
index.set_settings({
numericAttributesToIndex: %w(equalOnly(id))
})
在查询时,如果删除值周围的引号,则可以像在示例中那样传递它:
index.raw_search('Product title', {
filters: 'id!=65411'
# Your other parameters
})
字符串值
对于字符串值,您想将其添加到您的 attributesForFaceting
:
index.set_settings({
attributesForFaceting: %w(id)
})
然后这样查询:
index.raw_search('Product title', {
filters: 'id:-65411'
# Your other parameters
})
(排除的-
在facetFilters
documentation中有描述)
我正在尝试过滤 algolia 结果,并希望使用产品名称在我们的数据库中查找类似产品。我宁愿忽略当前产品,因此如果没有找到结果,将使用 removeWordsIfNoResults
选项。
我正在使用 Ruby api。
这基本上就是我正在尝试的方法,但它不起作用。是否可以过滤掉特定的objectID?
Product.raw_search("Men's Bridge & Burn Camden Steel Blue",
{ :hitsPerPage => 10,
:page => 0,
:attributesToRetrieve => "objectID",
:filters => "objectID != '65411'",
:removeWordsIfNoResults => 'lastWords'
}
)
objectID
是 Algolia 中的一个特定属性,它始终是一个字符串值,不能添加到 attributesForFaceting
中。
但是,如果您使用数据库中的 ID 填充它,则可以使用相同的值索引另一个属性(比方说 id
)。
数值
作为数值,您可以使用 Algolia 直接对其进行过滤。但是,由于您只会使用 !=
运算符,我建议您在 numericAttributesToIndex
列表中使用 equalOnly
修饰符声明它:
index.set_settings({
numericAttributesToIndex: %w(equalOnly(id))
})
在查询时,如果删除值周围的引号,则可以像在示例中那样传递它:
index.raw_search('Product title', {
filters: 'id!=65411'
# Your other parameters
})
字符串值
对于字符串值,您想将其添加到您的 attributesForFaceting
:
index.set_settings({
attributesForFaceting: %w(id)
})
然后这样查询:
index.raw_search('Product title', {
filters: 'id:-65411'
# Your other parameters
})
(排除的-
在facetFilters
documentation中有描述)