Algolia Rails 具有特定父 ID 的记录

Algolia Rails records with specific parent id

我不确定 algolia-rails gem(以及一般的 Algolia)是否朝着正确的方向前进:

目前我有这两个型号:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  belongs_to :account

  algoliasearch do
    attribute :account_id, :full_name, :email, :tax_id, :contact_name

    searchableAttributes ['full_name', 'email', 'tax_id', 'contact_name']

    customRanking ['asc(full_name)']
  end
end

class Account < ActiveRecord::Base
  has_many :contacts
end

我只想检索联系人索引中给定 account_id 的匹配记录,这样生成的查询就不会查找不属于特定帐户的联系人 ID。因此 current_account.contacts.algolia_search("Tom") 不应从其他帐户联系人获取 ID。

看起来它与刻面有关,但我不确定。

是的,这与刻面有很大关系。我修改了 Contact 模型以将其添加到 algoliasearch 块中:

attributesForFaceting ['account_id']

然后通过特定 account_id(假设 3)过滤与 "Tom" 匹配的联系人,这很简单:

Contact.algolia_search("Tom", {facets: 'account_id', facetFilters: "account_id:3"})