Giter Site home page Giter Site logo

santopuppy / redis-autosuggest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aphan/redis-autosuggest

0.0 1.0 0.0 105 KB

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

License: MIT License

redis-autosuggest's Introduction

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

redis-autosuggest's People

Watchers

Lester Celestial avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.