mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-01 13:10:58 -05:00
cleaning up the code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user