Download the PHP package etrepat/compleet without Composer

On this page you can find all versions of the php package etrepat/compleet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package compleet

Compleet

Latest Stable Version Total Downloads License Build Status

Compleet is a PHP port of the awesome Soulmate ruby gem, which was written by Eric Waller. All credit should go to the original library author.

This library will help you solve the common problem of developing a fast autocomplete feature. It uses Redis's sorted sets to build an index of partially completed words and the corresponding top matching items, and provides a simple interface to query them. Compleet finishes your sentences.

Compleet requires PHP >= 5.4 (or HHVM >= 3.2) and its only dependencies are Composer itself and the fantastic Predis PHP client library for Redis.

Getting Started

Compleet is distributed as a composer package, so kick things off by adding it as a requirement to your composer.json file:

Then update your packages by running composer update or install with composer install.

Usage

Compleet is designed to be simple and fast, and its main features are:

An item is a simple JSON object that looks like:

Where id is a unique identifier (within the specific type), term is the phrase you wish to provide completions for, score is a user-specified ranking metric (redis will order things lexicographically for items with the same score), and data is an optional container for metadata you'd like to return when this item is matched.

Managing items

Before being able to perform any autocomplete search we must first load some data into our redis database. To feed data into a Redis server instance for later querying, Compleet provides the Loader class:

The constructor parameter is the type of the items we are actually going to add/remove or load. We'll later use this same type for search. This is used so we can add several kinds of completeley differentiated data and index it into Redis separately.

By default a Compleet\Loader object will instatiate a connection to a local redis instance as soon as it is needed. If you wish to change this behaviour, you may either provide a connection into the constructor:

or use the setConnection method:

Loading items

Now that we have a loader object in place we probably want to use it to load a bunch of items into our redis database. Imagine we have the following PHP item array (which follows the previous JSON structure):

To load these items into Redis for later querying and previously clearing all existing data we have the load method:

Adding items

We may add a single item in a similar fashion with the add method:

The add method appends items individually without previously clearing the index.

For both the load and add methods, each item must supply the id and term array keys. All other attributes are optional.

Removing items

Similarly if we need to remove an individual item, the remove method will do just that:

Only the id key will be used and is actually mandatory.

Clearing the index

To wipe out all of the previously indexed data we may use the clear method:

Querying

Analogous to the Compleet\Loader class, Compleet provides the Matcher class which will allow us to query against previously indexed data. It works pretty similarly and accepts the same constructor arguments:

Again, the first constructor parameter is the type of the items we are actually going query against.

Then, the matches method will allow us to query the supplied term against the indexed data:

This will perform a search against the index of partially completed words for the venues type and it will return an array of matching items for the term stad. The resulting array will be sorted by the supplied score or alphabetically if none was given.

The matches method also supports passing an array of options as a second argument:

Setting the limit option to 0 will return all results which match the provided term.

Matching a single term against multiple types of items should be easy enough:

Working with the CLI

Compleet also provides a CLI utility, the compleet script, for easy data indexing from JSON documents/files. It may also be used to conduct queries for testing purposes. Like many composer packages which supply a binary, it will probably be placed under the vendor/bin folder of your project.

To load data into redis from the CLI, you can pipe items from a JSON file into the compleet load TYPE command.

Here's a sample venues.json (one JSON item per line):

And here's the load command (The compleet utility will assume redis is running locally on the default port, or you can specify a redis connection string with the --redis argument):

$ vendor/bin/compleet load venues < venues.json

Running compleet -h will list all the operations which are supported by the CLI and its arguments. All operations that may be performed programatically can be run from the compleet utility.

Using Compleet with your framework

Compleet is a standalone composer package and should work out of the box regardless of the PHP framework you use. In fact, none is needed.

Using Compleet with Laravel

A Compleet integration for Laravel >= 4.2 is provided in the Laravel Compleet package. It will help reduce the amount of boilerplate code needed to make the autocomplete functionality in your project useful and adds several nice integrations such as: global config, artisan commands, redis connection reuse, controller code, routes, etc.

Take a look at the Laravel Compleet project page for more information on how to use Compleet with your Laravel applications.

Contributing

Thinking of contributing? Maybe you've found some nasty bug? That's great news!

  1. Fork & clone the project: git clone [email protected]:your-username/compleet.git.
  2. Run the tests and make sure that they pass with your setup: phpunit.
  3. Create your bugfix/feature branch and code away your changes. Add tests for your changes.
  4. Make sure all the tests still pass: phpunit.
  5. Push to your fork and submit new a pull request.

License

Compleet is licensed under the terms of the MIT License (See LICENSE file for details).


Coded by Estanislau Trepat (etrepat). I'm also @etrepat on twitter.


All versions of compleet with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
predis/predis Version >=0.8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package etrepat/compleet contains the following files

Loading the files please wait ....