Giter VIP home page Giter VIP logo

flo's Introduction

flo

flo is a redis powered node.js autocompleter inspired by soulmate. You can use this anywhere you want since this is just a module. If you look into the examples folder, I have provided an example on how to get it work with express.

If you want see a real world example of this, you should try out the search box at SeatGeek or Quora.

Documentations

First, connect to the redis instance:

Sets up a new Redis Connection.

var flo = require('flo').connect();

options - Optional Hash of options.

  • redis - An existing redis connection to use.
  • host - String Redis host. (Default: Redis' default)
  • port - Integer Redis port. (Default: Redis' default)
  • password - String Redis password.
  • namespace - String namespace prefix for Redis keys. (Default: flo).
  • mincomplete - Minimum completion of keys required for auto completion. (Default: 1)
  • database - Integer of the Redis database to select.

Returns a Connection instance.

These are the public functions:

Add a new term

add_term(type, id, term, score, data, callback):

  • type - the type of data of this term (String)
  • id - unique identifier(within the specific type)
  • term - the phrase you wish to provide completions for
  • score - user specified ranking metric (redis will order things lexicographically for items with the same score)
  • data - container for metadata that you would like to return when this item is matched (optional)
  • callback - callback to be run (optional)

Returns nothing.

Search for a term

search_term(types, phrase, limit, callback):

  • types - types of term that you are looking for (Array of String)
  • phrase - the phrase or phrases you want to be autocompleted
  • limit - the count of the number you want to return (optional, default: 5)
  • callback(err, result) - err is the error and results is the results

This call:

search_term(["chinese", "indian"], "rice", 1, cb);

will return a result in json format like:

{
  term: "rice"
  chinese: [
      {
        id: 3,
        term: "mongolian fried rice",
        score: 10,
        data: {
          name: "Gonghu Chinese Restaurant",
          address: "304, University Avenue, Palo Alto"
        }
      }
    ],
   indian: [
      {
        id: 1,
        term: "Briyani Chicken Rice",
        score: 5,
        data: {
          name: "Bombay Grill",
          address: "100 Green St, Urbana"
        }
      }
    ]
}

Remove a term

remove_term(type, id, callback):

  • type - the type of data of this term (String)
  • id - unique identifier(within the specific type)
  • callback - callback to be run (optional)

Returns nothing.

Get the IDs for a term

get_ids (type, term, callback):

  • type - the type of data for this term
  • term - the term to find the unique identifiers for
  • callback(err, result) - result is an array of IDs for the term. Empty array if none were found

Get the data for an ID

get_data(type, id, callback):

  • type - the type of data for this term
  • id - unique identifier (within the specific type)
  • callback(err, result) - result is the data

For more information, you can read it here.

Tests

To run tests, first make sure your local redis is running, then:

./node_modules/expresso/bin/expresso test/*.test.js

License

MIT License


Author

Teng Siong Ong

Company

FLOChip

flo's People

Contributors

wred avatar siong1987 avatar

Watchers

 avatar

Forkers

jbpin

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.