Basic installation for multi-user search in pg_search and Rails 3.2.3

This is my first question here, after many months of concealment and absorption. Therefore, I hope I do it right.

I am trying to get the multi-user pg_search function working in my Rails 3.2.3 application after learning the pg_search_scope function from this Railscast.I believe that the pg_search documentation assumes that the reader has better knowledge of Rails than I have. I simply could not make the transition from the resources that I found to get a working application using multisearch. Any help is appreciated. Here is my setup:

configurations / initializers / pg_search.rb

PgSearch.multisearch_options = { :using => { :tsearch => { :dictionary => "english" }, :trigram => {} }, :ignoring => :accents } 

View Search Form

 <%= form_tag articles_path, method: :get do %> <%= text_field_tag :query, params[:query], :class => "search-box" %> <%= submit_tag "Search This Site", name: nil, :class => "btn btn-search" %> <% end %> 

article.rb

 include PgSearch multisearchable :against => [:title, :content] def self.search(query) if query.present? search(query) else scoped end end 

articles_controller.rb

 def index @articles = PgSearch.multisearch(params[:query]) respond_to do |format| format.html # index.html.erb format.json { render json: @articles } end end 

I do not get search results when searching for known terms. What am I doing wrong?

+2
source share
1 answer

It seems like my mistake was to use the @articles variable in my controller, and not to explicitly define @pg_search_documents , which I used in my opinion (which I completely forgot to post). For some reason, I thought that using @articles = PgSearch.multisearch(params[:query]) in my controller would add the search results to `@pg_search_documents' through the magic sauce pg_search.

+1
source

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


All Articles