phaniso/autocomplete

v1.0 2016-02-29 01:13 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:02 UTC


README

Scrutinizer Code Quality Coverage Status Build Status

利用trie数据结构的PHP自动完成库。

###安装

composer require phaniso/autocomplete

###如何使用

  1. 构建容器
use Autocomplete\Factory\ContainerFactory;

$containerFactory = new ContainerFactory;
$trie = $containerFactory->build('Trie');

默认情况下trie是区分大小写的,如果你想更改它,请将false作为参数传递

$trie = $containerFactory->build('Trie', [false]);

2.添加单词

$trie->addWord('randomWord');

3.使用前缀获取单词

$words = $trie->getByPrefix('random');

$words变量现在将包含一个具有'value'值为'randomWord'的元素