Provides autocompletions through Redis, with the ability to rank results and integrate with Rails
$ gem install redis-autosuggest
By default Autosuggest creates a new Redis client on db 0 at localhost:6379.
To change the server/port:
r = Redis.new(:host => "my_host", :port => my_port)
Redis::Autosuggest.redis = rTo add items to be use for autocompletions:
Redis::Autosuggest.add("North By Northwest", "Northern Exposure")To check for autocompletions for an item:
Redis::Autosuggest.suggest("nor")
# => ["north by northwest", "northern exposure"]Autocompletions will be ordered their score value (descending).
Some other usage examples:
# Add items with initial scores
Redis::Autosuggest.add_with_score("North By Northwest", 9, Northern Exposure, 3)
# Increment an item's score
Redis::Autosuggest.increment("North By Northwest", 1)Fuzzy matching:
Redis::Autosuggest.fuzzy_match = true
Redis::Autosuggest.add("North By Northwest")
Redis::Autosuggest.suggest("nort byenorthwest")
# => ["north by northwest"]Autosuggest can also be integrated with Rails. Include it in a model:
class Movie < ActiveRecord::Base
include Redis::Autosuggest
attr_accessible :movie_title
autosuggest :movie_title
endFor first time usage, seed the Redis db with the autosuggest sources:
rake autosuggest:initYou can optionally specify a numeric field to be used as the initial score for an item when it is added and a limit of how many items maximum to keep:
autosuggest :movie_title, :rank_by => imdb_rating, limit => 10000Jquery plugin for dropdown autocompletions for a from can be found here