Created
March 19, 2019 16:52
-
-
Save julienbourdeau/72708c2dcaa7098fddbba7dcd13d5e0b to your computer and use it in GitHub Desktop.
Rails Algolia: Create subindex but without main index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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