Implementing Universal Rail Search 4

I have an application with rails 4 with the number of models and page views. The app layout of my app contains a search bar. But now it is inactive. The purpose of the search bar is to allow the user to search all models for the entered keywords, basically making it a global search. Is there a gem that does a universal search? Or does it need to be done manually through sql queries? I could see a way to implement a search for a specific model on my browse page. But I want him to look through all the models at once. How can I do it?

+6
source share
3 answers

I think the best way in your case is to use ElasticSearch. Here's a neat integration crystal here . Documentation links are provided on this page.

+5
source

Sunspot is one of the most used stones for adding search to a Rails application.

Indexing is as follows:

class Post < ActiveRecord::Base searchable do text :title, :body text :comments do comments.map { |comment| comment.body } end integer :blog_id integer :author_id integer :category_ids, :multiple => true time :published_at string :sort_title do title.downcase.gsub(/^(an?|the)\b/, '') end end end 

And the search:

 Post.search do fulltext 'best pizza' with :blog_id, 1 with(:published_at).less_than Time.now order_by :published_at, :desc paginate :page => 2, :per_page => 15 facet :category_ids, :author_id end 
+3
source

One good approach to this would be to use the gem 'searchkick' which uses search elastics.

Search Resources: https://github.com/ankane/searchkick https://github.com/ankane/searchkick#advanced

+3
source

Source: https://habr.com/ru/post/983627/


All Articles