2017 © Pedro Peláez
 

library redcard

Autocomplete implementation using PHP and Redis

image

jsidorenko/redcard

Autocomplete implementation using PHP and Redis

  • Tuesday, April 5, 2016
  • by jsidorenkko
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

RedCard Autocomplete

Autocomplete implementation using PHP+Redis., (*1)

Inspired by https://github.com/seatgeek/soulmate, (*2)

This library handles a basic implementation of autocomplete with sorted results (according to "scores") as well as arbitrary metadata for results. Also has the ability to separate different autocomplete databases in to "bins" (e.g. have separate bins "users" and another for "videos" so when querying against "users" it doesn't show results from "videos"), (*3)

Installation

Add mochaka/redcard as a requirement to composer.json:, (*4)

{
    "require": {
        "jsidorenko/redcard": "dev-master"
    }
}

Update your packages with composer update or install with composer install., (*5)

Integration

You will need to create a Predis Client Instance and provide it to the autocomplete class., (*6)

    $redis = new Predis\Client(array(
        'scheme' => 'tcp',
        'host'   => 'localhost',
        'port'   => 6379,
    ));

    $autocomplete = new JSidorenko\RedCard\RedisAutocomplete( $redis );
    or
    $autocomplete = new JSidorenko\RedCard\RedisAutocomplete( $redis, "yourDomainPrefix" );

    instead of "yourDomainPrefix" you can write something like "users" or "locations"

Basic Usage

To store data you must have a unique ID for an item and the phrase that should be searchable., (*7)


$autocomplete->store(2, "cat"); $autocomplete->store(3, "care"); $autocomplete->store("MYCRAZYID", "caress"); $autocomplete->store(55, "cars"); $autocomplete->store(6, "camera"); $results = $autocomplete->find("car"); var_dump($results)

Bins

Different types of data can be distinguished from one another through bins. Each bin has its own name and when searching and removing they will not conflict with one another., (*8)


$autocomplete->store(2, "Mary", "users"); $autocomplete->store(3, "Sally", "users"); $autocomplete->store(4, "Leo", "users" ); $autocomplete->store(5, "Mary Had A Litte Lamb", "blog-title"); $autocomplete->store(6, "Redis Rocks, A Life Story", "blog-title"); $results = $autocomplete->find("Mary", "users"); // Will only return Mary instead of "Mary Had A Litte Lamb"

Interface

The basic functions that you need to be aware of to utilize RedCard., (*9)

  • store: store a new item to autocomplete, (*10)

        store($id, $phrase, $bin = '', $score = 1, $data = NULL)
    

    example, (*11)

        $autocomplete->store('id123', "Clockwork Orange", "Books", 3, array('author'=>'Anthony Burgess'))
    
  • find: find an item. Searches are cached in a seperate hash., (*12)

        find($phrase, $bin = '', $count = 10, $isCaching = true)
    

    example, (*13)

        $autocomplete->find("Clock", "Books", 1, true)
    
  • find by ID: find an item by provided ID. Returns null if nothing found., (*14)

        findByID($id, $bin = '')
    

    example, (*15)

        $autocomplete->findByID('id123')
    
  • remove: remove an item from a bin. Searches are cached in a separate hash., (*16)

        remove($id, $bin = '')
    

    example, (*17)

        $autocomplete->remove('id123', 'Books')
    
  • clear: clear all items., (*18)

        clear()
    

    example, (*19)

        $autocomplete->clear()
    

License

RedCard Autocomplete is licensed under the MIT License. Original Copyright (c) 2011 Rishi Ishairzay, released under the MIT license, (*20)

The Versions

05/04 2016

dev-master

9999999-dev https://github.com/jsidorenko/RedCard-Autocomplete

Autocomplete implementation using PHP and Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Rishi Ishairzay
by Luke Nilaratna

laravel cache redis search autocomplete

05/04 2016

v1.1

1.1.0.0 https://github.com/jsidorenko/RedCard-Autocomplete

Autocomplete implementation using PHP and Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Rishi Ishairzay
by Luke Nilaratna

laravel cache redis search autocomplete

28/06 2015

v1.0

1.0.0.0 https://github.com/VictorSigma/RedCard-Autocomplete

Autocomplete implementation using PHP and Redis

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rishi Ishairzay
by Luke Nilaratna

laravel cache redis search autocomplete