Ruby on Rails - searchkick in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Searchkick in ruby on rails
If you want to setup quickly elasticsearch you can use the searchkick gem :
gem 'searchkick'
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Add searchkick to models you want to search.
class Product < ActiveRecord::Base
searchkick
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Add data to the search index
Product.reindex
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
And to query, use:
products = Product.search "apples"
products.each do |product|
puts product.name
end