use elasticsearch for auto-suggest

This commit is contained in:
Shiho Takagi committed 2015-01-20 13:20:13 +11:00
1 parent 666d6dac48
commit f910fdfa73
2 files changed
+3 -12

No files matched your search

+1 -1
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
+2 -11
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