mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-05 07:01:03 -05:00
use elasticsearch for auto-suggest
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user