diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 7a9e227b9..4bf2e1b9c 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -62,7 +62,7 @@ class CropsController < ApplicationController respond_to do |format| format.html format.json { - render :json => @all_matches + render :json => Crop.autosuggest(params[:term]) } end end diff --git a/app/models/crop.rb b/app/models/crop.rb index f43ba1894..371fcb263 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -42,7 +42,7 @@ class Crop < ActiveRecord::Base tokenizer: { gs_edgeNGram_tokenizer: { type: "edgeNGram", - min_gram: 1, + min_gram: 2, max_gram: 20, token_chars: [ "letter", "digit" ] } @@ -261,4 +261,8 @@ class Crop < ActiveRecord::Base ) response.records.to_a end + + def self.autosuggest(term) + where("name ILIKE ?", "%#{term}%") + end end