diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 5d71b21dc..07c4ccf39 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -58,7 +58,7 @@ class CropsController < ApplicationController respond_to do |format| format.html - format.json { render :json => Crop.autosuggest(params[:term]) } + format.json { render :json => Crop.search(params[:term]) } end end diff --git a/app/models/crop.rb b/app/models/crop.rb index 7c0461e39..d6937b838 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -40,8 +40,8 @@ class Crop < ActiveRecord::Base tokenizer: { gs_edgeNGram_tokenizer: { type: "edgeNGram", - min_gram: 2, - max_gram: 20, + min_gram: 4, + max_gram: 10, token_chars: [ "letter", "digit" ] } }, @@ -256,13 +256,4 @@ class Crop < ActiveRecord::Base ) return response.records.to_a end - - # Crop.autosuggest(string) - # ActiveRecord search is used for auto-suggest instead of Elasticsearch. - # This is to avoid confusing users since the drop-down list for auto-suggest - # only caters for crop names at this time, not including scientific names or - # alternative names. - def self.autosuggest(term) - where("name ILIKE ?", "%#{term}%") - end end