Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rap2hpoutre/similar-text-finder
:honeybee: PHP Similar Text Finder aka Fuzzy search. `Did you mean "banana"?`
https://github.com/rap2hpoutre/similar-text-finder
composer fuzzy-search hacktoberfest php search text-finder
Last synced: 9 days ago
JSON representation
:honeybee: PHP Similar Text Finder aka Fuzzy search. `Did you mean "banana"?`
- Host: GitHub
- URL: https://github.com/rap2hpoutre/similar-text-finder
- Owner: rap2hpoutre
- License: mit
- Created: 2015-04-21T05:41:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-01T06:42:37.000Z (about 1 year ago)
- Last Synced: 2024-10-14T10:46:26.598Z (27 days ago)
- Topics: composer, fuzzy-search, hacktoberfest, php, search, text-finder
- Language: PHP
- Homepage: http://twitter.com/rap2h
- Size: 26.4 KB
- Stars: 136
- Watchers: 11
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Similar Text Finder
[![Packagist](https://img.shields.io/packagist/l/rap2hpoutre/similar-text-finder.svg)](https://packagist.org/packages/rap2hpoutre/similar-text-finder)
[![Code Coverage](https://scrutinizer-ci.com/g/rap2hpoutre/similar-text-finder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/rap2hpoutre/similar-text-finder/?branch=master)
[![Packagist](https://img.shields.io/packagist/dt/rap2hpoutre/similar-text-finder.svg)](https://packagist.org/packages/rap2hpoutre/similar-text-finder)
## TL;DRSimilar text finder. Install via composer, works with any framework: Laravel, Slim, Symfony, etc.
![screenshot](https://cloud.githubusercontent.com/assets/1575946/7246876/1b15c4c0-e803-11e4-91d8-a2e7cd5a0f0c.png)
```php
// Init Similar Text Finder with a needle and a haystack
$text_finder = new \SimilarText\Finder('bananna', ['apple', 'banana', 'kiwi']);// Get first similar word (it's banana)
echo $text_finder->first();
```## Installation
Install with composer
`composer require rap2hpoutre/similar-text-finder`.
That's all.You can now use it in your framework's controller, or wherever you want (you don't need a framework anyway).
## Usage
### Quick start
Just build a new Similar Text Finder like this:
```php
$tf = new \SimilarText\Finder($needle, $haystack);
```
`$needle` may be the user input and `$haystack` should be an array with all your suggestion. You can display the closest response like this:
```php
echo 'Did you mean ' $tf->first() . ' ?';
```
Or use it in your favorite template engine (Twig, Blade, etc.)You can get all your suggestion ordered by most approching words like this:
```php
$all = $tf->all();
```### Example in raw PHP
```php
use SimilarText\Finder;// User input with a typo (you could get it from $_GET)
$needle = 'tmatoes';// Your list (from your database or an API)
$haystack = ['salad', 'tomatoes', 'onions', 'mates'];// Init Text Finder
$finder = new Finder($needle, $haystack);// Display all results ordered by the most approching
$results = $finder->all();
echo implode(', ', $results);// You should see something like "tomatoes, mates, onions, salad", yohoo.
```