Download the PHP package loilo/fuse without Composer

On this page you can find all versions of the php package loilo/fuse. 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 fuse

![The Fuse logo, a violet asterisk, in reference to the Fuse.js logo](fuse.svg)

Fuse

A fuzzy search library for PHP

Tests Packagist PHP Version

This is a PHP port of the awesome Fuse.js project and aims to provide full API compatibility wherever possible.

Check out their demo and examples to get a good feel for what this library is capable of.

Latest compatible Fuse.js version: 7.0.0


Table of Contents:


Installation

This package is available via Composer. To add it to your project, just run:

Note that at least PHP 7.4 is needed to use Fuse.

Usage

Here's a simple usage example:

This leads to the following results (where each result's item refers to the matched entry itself and refIndex provides the item's position in the original $list):

Options

Fuse has a lot of options to refine your search:

Basic Options

isCaseSensitive

Indicates whether comparisons should be case sensitive.


includeScore

Whether the score should be included in the result set. A score of 0 indicates a perfect match, while a score of 1 indicates a complete mismatch.


includeMatches

Whether the matches should be included in the result set. When true, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes.


minMatchCharLength

Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to 2).


shouldSort

Whether to sort the result list, by score.


findAllMatches

When true, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string.


keys

List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of strings and objects.


Fuzzy Matching Options

location

Determines approximately where in the text is the pattern expected to be found.


threshold

At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.


distance

Determines how close the match must be to the fuzzy location (specified by location). An exact letter match which is distance characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified. A distance of 1000 would require a perfect match to be within 800 characters of the location to be found using a threshold of 0.8.


ignoreLocation

When true, search will ignore location and distance, so it won't matter where in the string the pattern appears.

Tip: The default options only search the first 60 characters. This should suffice if it is reasonably expected that the match is within this range. To modify this behavior, set the appropriate combination of location, threshold, distance (or ignoreLocation).

To better understand how these options work together, read about Fuse.js' Scoring Theory.


Advanced Options

useExtendedSearch

When true, it enables the use of unix-like search commands. See example.


getFn

The function to use to retrieve an object's value at the provided path. The default will also search nested paths.


sortFn

The function to use to sort all the results. The default will sort by ascending relevance score, ascending index.


ignoreFieldNorm

When true, the calculation for the relevance score (used for sorting) will ignore the field-length norm.


Tip: The only time it makes sense to set ignoreFieldNorm to true is when it does not matter how many terms there are, but only that the query term exists.

fieldNormWeight

Determines how much the field-length norm affects scoring. A value of 0 is equivalent to ignoring the field-length norm. A value of 0.5 will greatly reduce the effect of field-length norm, while a value of 2.0 will greatly increase it.


Global Config

You can access and manipulate default values of all options above via the config method:

Methods

The following methods are available on each Fuse\Fuse instance:


search

Searches the entire collection of documents, and returns a list of search results.

The $pattern can be one of:

The $options:


setCollection

Set/replace the entire collection of documents. If no index is provided, one will be generated.

Example:


add

Adds a doc to the collection and update the index accordingly.

Example:


remove

Removes all documents from the list which the predicate returns truthy for, and returns an array of the removed docs. The predicate is invoked with two arguments: ($doc, $index).

Example:


removeAt

Removes the doc at the specified index.

Example:


getIndex

Returns the generated Fuse index.

Example:

Indexing

The following methods are available on each Fuse\Fuse instance:


Fuse::createIndex

Pre-generate the index from the list, and pass it directly into the Fuse instance. If the list is (considerably) large, it speeds up instantiation.

Example:

Fuse::parseIndex

Parses a JSON-serialized Fuse index.

Example:

Differences with Fuse.js

  Fuse.js PHP Fuse
Get Fuse Version Fuse.version
Access global configuration Fuse.config property Fuse::config method
List modification Using fuse.add() etc. modifies the original list passed to the new Fuse constructor. In PHP, arrays are a primitive data type, which means that your original list is never modified by Fuse. To receive the current list after adding/removing items, the $fuse->getCollection() method can be used.

Development

Project Scope

Please note that I'm striving for feature parity with Fuse.js and therefore will add neither features nor fixes to the search logic that are not reflected in Fuse.js itself.

If you have any issues with search results that are not obviously bugs in this PHP port, and you happen to know JavaScript, please check if your use case works correctly in the online demo of Fuse.js as that is the canonical Fuse implementation. If the issue appears there as well, please open an issue in their repo.

Setup

To start development on Fuse, you need git, PHP (≥ 7.4) and Composer.

Since code is formatted using Prettier, it's also recommended to have Node.js/npm installed as well as using an editor which supports Prettier formatting.

Clone the repository and cd into it:

Install Composer dependencies:

Install npm dependencies (optional but recommended). This is only needed for code formatting as npm dependencies include Prettier plugins used by this project.

Quality Assurance

There are different kinds of code checks in place for this project. All of these are run when a pull request is submitted but can also be run locally:

Command Purpose Description
vendor/bin/phpcs check code style Run PHP_CodeSniffer to verify that the Fuse source code abides by the PSR-12 coding style.
vendor/bin/psalm static analysis Run Psalm against the codebase to avoid type-related errors and unsafe coding patterns.
vendor/bin/phpunit check program logic Run all PHPUnit tests from the test folder.

Contributing

Before submitting a pull request, please add relevant tests to the test folder.


All versions of fuse with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^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 loilo/fuse contains the following files

Loading the files please wait ....