All Projects → loilo → Fuse

loilo / Fuse

Licence: apache-2.0
🔍 Fuzzy search for PHP based on the Bitap algorithm

Projects that are alternatives of or similar to Fuse

Fuzzysearch
🐷 Tiny and fast fuzzy search in Go
Stars: ✭ 602 (+218.52%)
Mutual labels:  algorithm, fuzzy-search
Flexsearch
Next-Generation full text search library for Browser and Node.js
Stars: ✭ 8,108 (+4189.95%)
Mutual labels:  search, fuzzy-search
Ugrep
🔍NEW ugrep v3.1: ultra fast grep with interactive query UI and fuzzy search: search file systems, source code, text, binary files, archives (cpio/tar/pax/zip), compressed files (gz/Z/bz2/lzma/xz/lz4), documents and more. A faster, user-friendly and compatible grep replacement.
Stars: ✭ 626 (+231.22%)
Mutual labels:  search, fuzzy-search
Algorithms
Minimal examples of data structures and algorithms in Python
Stars: ✭ 20,123 (+10547.09%)
Mutual labels:  algorithm, search
List.js
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.
Stars: ✭ 10,650 (+5534.92%)
Mutual labels:  search, fuzzy-search
Cassandra Lucene Index
Lucene based secondary indexes for Cassandra
Stars: ✭ 584 (+208.99%)
Mutual labels:  search, fuzzy-search
Minisearch
Tiny and powerful JavaScript full-text search engine for browser and Node
Stars: ✭ 737 (+289.95%)
Mutual labels:  search, fuzzy-search
Tntsearch
A fully featured full text search engine written in PHP
Stars: ✭ 2,693 (+1324.87%)
Mutual labels:  search, fuzzy-search
Elassandra
Elassandra = Elasticsearch + Apache Cassandra
Stars: ✭ 1,610 (+751.85%)
Mutual labels:  search, fuzzy-search
Javascript
A repository for All algorithms implemented in Javascript (for educational purposes only)
Stars: ✭ 16,117 (+8427.51%)
Mutual labels:  algorithm, search
Jstarcraft Rns
专注于解决推荐领域与搜索领域的两个核心问题:排序预测(Ranking)和评分预测(Rating). 为相关领域的研发人员提供完整的通用设计与参考实现. 涵盖了70多种排序预测与评分预测算法,是最快最全的Java推荐与搜索引擎.
Stars: ✭ 324 (+71.43%)
Mutual labels:  algorithm, search
C Plus Plus
Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
Stars: ✭ 17,151 (+8974.6%)
Mutual labels:  algorithm, search
Textrank
🌀 ⚡️ 🌍 TextRank (automatic text summarization) for PHP8
Stars: ✭ 193 (+2.12%)
Mutual labels:  algorithm, search
Typesense
Fast, typo tolerant, fuzzy search engine for building delightful search experiences ⚡ 🔍 ✨ An Open Source alternative to Algolia and an Easier-to-Use alternative to ElasticSearch.
Stars: ✭ 8,644 (+4473.54%)
Mutual labels:  search, fuzzy-search
Scoper
Fuzzy and semantic search for captioned YouTube videos.
Stars: ✭ 225 (+19.05%)
Mutual labels:  search, fuzzy-search
Dsa.js Data Structures Algorithms Javascript
🥞Data Structures and Algorithms explained and implemented in JavaScript + eBook
Stars: ✭ 6,251 (+3207.41%)
Mutual labels:  algorithm, search
Monster
The Art of Template MetaProgramming (TMP) in Modern C++♦️
Stars: ✭ 90 (-52.38%)
Mutual labels:  algorithm, search
Similar Text Finder
🐝 PHP Similar Text Finder aka Fuzzy search. `Did you mean "banana"?`
Stars: ✭ 126 (-33.33%)
Mutual labels:  search, fuzzy-search
Algorithm
The repository algorithms implemented on the Go
Stars: ✭ 163 (-13.76%)
Mutual labels:  algorithm, search
Dtl
diff template library written by C++
Stars: ✭ 180 (-4.76%)
Mutual labels:  algorithm

The Fuse logo, a violet asterisk, in reference to the Fuse.js logo

Fuse

Tests Packagist

A fuzzy search library for PHP based on the Bitap algorithm

This is a PHP port of the awesome Fuse.js project and provides 100% API compatibility.

Latest compatible Fuse.js version: 3.6.1

For an approximate demonstration of what this library can do, check out their demo & usage.

Installation

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

composer require loilo/fuse

Usage

<?php
require_once 'vendor/autoload.php';

$fuse = new \Fuse\Fuse([
  [
    "title" => "Old Man's War",
    "author" => "John Scalzi"
  ],
  [
    "title" => "The Lock Artist",
    "author" => "Steve Hamilton"
  ],
  [
    "title" => "HTML5",
    "author" => "Remy Sharp"
  ],
  [
    "title" => "Right Ho Jeeves",
    "author" => "P.D Woodhouse"
  ],
], [
  "keys" => [ "title", "author" ],
]);

$fuse->search('hamil');

/*
Array
(
  [0] => Array
    (
      [title] => The Lock Artist
      [author] => Steve Hamilton
    )
  [1] => Array
    (
      [title] => HTML5
      [author] => Remy Sharp
    )
)
*/

Options

keys (type: array)

List of properties that will be searched. This supports nested properties, weighted search, searching in arrays of strings and associative arrays etc:

$books = [
  [
    "title" => "Old Man's War",
    "author" => [
      "firstName" => "John",
      "lastName" => "Scalzi"
    ]
  ]
];
$fuse = new \Fuse\Fuse($books, [
  "keys" => [ "title", "author.firstName" ]
]);

id (type: string)

The name of the identifier property. If specified, the returned result will be a list of the items' identifiers, otherwise it will be a list of the items.


caseSensitive (type: bool, default: false)

Indicates whether comparisons should be case sensitive.


includeScore (type: bool, default: false)

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 (type: bool, default: false)

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: "indices" => [ $start, $end ]. These can consequently be used for highlighting purposes.


shouldSort (type: bool, default: true)

Whether to sort the result list, by score.


getFn (type: function, default: \Fuse\Helpers\deep_value)

The get function to use when fetching an associative array's properties. The default will search nested paths like foo.bar.baz.

/*
 * @param {array|object} $data The object or associative array being searched
 * @param {string}       $path The path to the target property
 */

'getFn' => function ($data, $path) {
    // Example using a ->get() method on objects and simple index access on arrays
    return is_object($data)
        ? $data->get($path)
        : $data[$path];
}

sortFn (type: function, default: sort by score)

The function that is used for sorting the result list.


location (type: int, default: 0)

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


threshold (type: float, default: 0.6)

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 (type: int, default: 100)

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.


maxPatternLength (type: int, default: 32)

The maximum length of the search pattern. The longer the pattern, the more intensive the search operation will be. Whenever the pattern exceeds the maxPatternLength, an error will be thrown. Why is this important? Read this.


verbose (type: bool, default: false)

Will print out steps. Useful for debugging.


tokenize (type: bool, default: false)

When true, the search algorithm will search individual words and the full string, computing the final score as a function of both. Note that when tokenize is true, the threshold, distance, and location are inconsequential for individual tokens.


tokenSeparator (type: string, default: / +/g)

A regular expression string used to separate words of the search pattern when searching. Only applicable when tokenize is true.


matchAllTokens (type: bool, default: false)

When true, the result set will only include records that match all tokens. Will only work if tokenize is also true.


findAllMatches (type: bool, default: false)

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.


minMatchCharLength (type: int, default: 1)

When set to include matches, only those whose length exceeds this value will be returned. (For instance, if you want to ignore single character index returns, set to 2)

Methods

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


search($pattern)

/*
@param {string} $pattern The pattern string to fuzzy search on.
@return {array} A list of all search matches.
*/

Searches for all the items whose keys (fuzzy) match the pattern.


setCollection($list)

/*
@param {array}  $list The new data to use
@return {array}       The provided $list
*/

Sets a new list of data for Fuse to match against.

Weighted Search

In some cases you may want certain keys to be weighted differently for more accurate results. You may provide each key with a custom weight (where 0 < weight <= 1):

$fuse = new \Fuse\Fuse($books, [
  "keys" => [
    [
      "name" => "title",
      "weight" => 0.3
    ],
    [
      "name" => "author",
      "weight" => 0.7
    ]
  ]
]);

Contributing

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

Please note that I'm striving for feature parity with the original Fuse.js and therefore won't add own features beyond bug fixes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].