承接 jsidorenko/redcard 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jsidorenko/redcard

Composer 安装命令:

composer require jsidorenko/redcard

包简介

Autocomplete implementation using PHP and Redis

README 文档

README

Autocomplete implementation using PHP+Redis.

Inspired by https://github.com/seatgeek/soulmate

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")

Installation

Add mochaka/redcard as a requirement to composer.json:

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

Update your packages with composer update or install with composer install.

Integration

You will need to create a Predis Client Instance and provide it to the autocomplete class.

    $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.

$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.

$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.

  • store: store a new item to autocomplete

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

    example

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

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

    example

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

         findByID($id, $bin = '')

    example

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

         remove($id, $bin = '')

    example

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

         clear()

    example

         $autocomplete->clear()

License

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

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固