Created
May 25, 2018 23:21
-
-
Save wykhuh/c6c1fbb3017d72b0bbb5b4233e4edcbc to your computer and use it in GitHub Desktop.
autocomplete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AutocompleteController < ApplicationController | |
def index | |
query = params[:query].downcase | |
taxa = ::Taxon.where('lower("name") like ?', "#{query}%") | |
.limit(10) | |
render json: taxa | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddTaxaIndex < ActiveRecord::Migration[5.0] | |
def change | |
execute 'CREATE INDEX name_prefix ON taxa USING btree (lower ("name") text_pattern_ops);' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment