如何过滤Algolia结果并省略特定的objectID

时间:2016-07-07 00:03:53

标签: algolia

我正在尝试过滤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' 
  }
)

1 个答案:

答案 0 :(得分:7)

DateTime date; if (!DateTime.TryParseExact(inputString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None, out date)) { } 是Algolia中的一个特定属性,始终为字符串值,无法添加到objectID。 但是,如果您使用数据库中的ID填充它,则可以使用相同的值索引另一个属性(假设为attributesForFaceting)。

数值

作为数值,您可以使用Algolia直接对其进行过滤。但是,由于您只使用id运算符,因此我建议您使用!=修饰符在numericAttributesToIndex列表中声明它:

equalOnly

在查询时,如果删除值周围的引号,则可以像在示例中那样传递它:

index.set_settings({
  numericAttributesToIndex: %w(equalOnly(id))
})

字符串值

使用字符串值,您希望将其添加到attributesForFaceting

index.raw_search('Product title', {
  filters: 'id!=65411'
  # Your other parameters
})

然后像这样查询:

index.set_settings({
  attributesForFaceting: %w(id)
})

(排除的index.raw_search('Product title', { filters: 'id:-65411' # Your other parameters }) facetFilters documentation

中有所描述
相关问题