0

Currently working with the Searchkick gem and trying to figure out how to search with multiple queries at the same time.

I want the search queries to be pre-defined using a select (drop down).

My controller looks like this currently:

  def index
    @application = Application.search(params[:query])
 end

and my view:

<%= form_tag search_company_path, method: :get do %>
 <p>
  <%= label_tag :query, "Type" %>
  <%= select_tag :query, options_for_select(['Test 1','Test 2','Test 3', 'Test 4',    'Test 5']) %>
  <%= label_tag :query, "On location?" %>
  <%= select_tag :query, options_for_select(['Yes', 'No', 'Either']) %>
  <%= submit_tag "Search", name: nil %>
 </p>
<% end %>

this works to run two select_tags with the same :query, but I'm guessing that ain't very nice coding. Nor can I create a label_tag for the latter.

Also if I perform a successful search it resets the select_tag to the 1st (test 1 and Yes), how do I fix this as-well?

user2755537
  • 151
  • 1
  • 9

1 Answers1

0

I meet the same problem when I use searchkick in rails. Elasticsearch published its officially project

https://github.com/elasticsearch/elasticsearch-rails

Here is the document of multiple query string method: elasticsearch-multiple query string The project of elasticsearch-rails' companion elasticsearch-model can help us.

response = Article.search query:     { bool: { should: [match:  { title: "Fox Dogs" },
                                                        match:  { author: 'Will' }] } },
                          highlight: { fields: { title: {} } }
Jameson
  • 71
  • 1
  • 6