No commit activity in last 3 years
No release in over 3 years
Provides autocompletions through Redis, with the ability to rank results and integrate with Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.3.3

Runtime

~> 3.0.3
~> 1.2.1
 Project Readme

Redis::Autosuggest

Provides autocompletions through Redis, with the ability to rank results and integrate with Rails

Installation

$ gem install redis-autosuggest

Usage

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 = r

To 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"]

Rails support

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
end

For first time usage, seed the Redis db with the autosuggest sources:

rake autosuggest:init

You 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 => 10000

Front-end portion

Jquery plugin for dropdown autocompletions for a from can be found here