auto-suggest to use existing search

This commit is contained in:
Shiho Takagi
2015-01-17 00:31:01 +11:00
parent 619e8590c8
commit 06c7703628
2 changed files with 6 additions and 2 deletions

View File

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

View File

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