cleaning up the code

This commit is contained in:
Shiho Takagi
2015-01-17 18:28:45 +11:00
parent b4cd151a03
commit ad7cfdabd0
3 changed files with 8 additions and 8 deletions

View File

@@ -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)

View File

@@ -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 }

View File

@@ -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