Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Created March 19, 2019 16:52
Show Gist options
  • Save julienbourdeau/72708c2dcaa7098fddbba7dcd13d5e0b to your computer and use it in GitHub Desktop.
Save julienbourdeau/72708c2dcaa7098fddbba7dcd13d5e0b to your computer and use it in GitHub Desktop.
Rails Algolia: Create subindex but without main index.
class Contact < ApplicationRecord
include AlgoliaSearch
algoliasearch per_environment: true, if: :turn_off_main_index do
add_index "CONTACT_subset", if: :subset? do
attributes :name, :email, :company, :state
searchableAttributes ['name', 'company', 'unordered(email)']
attributesForFaceting ['company', 'state']
end
end
def turn_off_main_index
false
end
def subset?
['CA', 'IL'].include?(state)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment