What is SearchKick Gem?
Searchkick Gem is a Ruby on Rails gem that runs on top of Elasticsearch and makes it easy searches in a Rails-friendly fashion. Searchkick supports the complete Elasticsearch Search API, as by using it our search becomes more advanced. In addition, it allows you to add more features including analytics, auto suggestions, and personalized results.The steps are required:
- Add the gem “gem ‘searchkick’“.
- Then run the bundle install command.
rails g scaffold Article name:string description:textAfter running the above command it will generate all the necessary files then we will run the database migration command.
rake db:migrateThe controller code will be modified like that
Def index Query=params[:q].presence || “*” @artivles=Article.search( query, page: params[:page}, per_page: 25 ) endThe model code will be modified like that
searchkick def search_data { title: title } endThe view code for display the articles will be modified like these.
Before starting the application we need to create the indexes
rake searchkick:reindex CLASS=ArticleThe ouput of the application look like these.
Source: Data Search in ROR using SearchKick Gem
It is nice blog Thank you provide important information and I am searching for the same information to save my time Ruby on Rails Online Training Bangalore
ReplyDelete