Created
February 27, 2017 20:19
-
-
Save mhulet/22b568c91a2daf37ebb49e77e480e9dc to your computer and use it in GitHub Desktop.
Rails 4 / Algolia setup for indexing a model
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
# config/initializers/algolia.rb | |
AlgoliaSearch.configuration = { | |
application_id: ENV["ALGOLIA_APPLICATION_ID"], | |
api_key: ENV["ALGOLIA_ADMIN_API_KEY"] | |
} |
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
gem "algoliasearch-rails", "~> 1.18.0" |
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
# app/models/post.rb | |
class Note < ActiveRecord::Base | |
include AlgoliaSearch | |
algoliasearch sanitize: true, index_name: ENV['ALGOLIA_INDEX_NAME'] do | |
attributes :title, :content | |
searchableAttributes ['title', 'content'] | |
tags do | |
[ | |
"user_#{self.user.token}" | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment