use elasticsearch for auto-suggest

This commit is contained in:
Shiho Takagi
2015-01-19 15:45:59 +11:00
parent 666d6dac48
commit f910fdfa73
2 changed files with 3 additions and 12 deletions

View File

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

View File

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