diff --git a/app/models/crop.rb b/app/models/crop.rb index 6c32b0049..38781333b 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -245,19 +245,18 @@ class Crop < ActiveRecord::Base # searches for crops whose names match the string given # just uses SQL LIKE for now, but can be made fancier later def self.search(query) - search_str = query.nil? ? "" : "#{query.downcase}" - response = __elasticsearch__.search( - { + search_str = query.nil? ? "" : query.downcase + response = __elasticsearch__.search( { query: { multi_match: { - query: search_str, + query: "#{search_str}", fields: ["name", "scientific_names.scientific_name", "alternate_names.name"] } }, size: 50 } ) - response.records.to_a + return response.records.to_a end def self.autosuggest(term) diff --git a/app/views/crops/search.html.haml b/app/views/crops/search.html.haml index 082bfde9e..2ed095402 100644 --- a/app/views/crops/search.html.haml +++ b/app/views/crops/search.html.haml @@ -1,6 +1,6 @@ - content_for :title, "Crops matching #{@search}" -- unless (@all_matches.length > 0) +- if @all_matches.empty? %h2 No results found %p Sorry, we couldn't find any crops that matched your search for "#{@search}". @@ -9,9 +9,10 @@ = link_to "browsing our crop database", crops_path instead. -- if ! @all_matches.empty? +- else %div#all_matches .row - @all_matches.each do |c| .col-md-2.six-across = render :partial => "thumbnail", :locals => { :crop => c } + diff --git a/spec/views/crops/search.html.haml_spec.rb b/spec/views/crops/search.html.haml_spec.rb index 8878f01c0..8458f254e 100644 --- a/spec/views/crops/search.html.haml_spec.rb +++ b/spec/views/crops/search.html.haml_spec.rb @@ -21,7 +21,7 @@ describe "crops/search" do end end - it "shows all matches" do + it "shows partial matches" do assert_select "div#all_matches" do assert_select "a[href=#{crop_path(@roma)}]" end