PHPackages                             fza/mysql-doctrine-jaro-winkler-function - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fza/mysql-doctrine-jaro-winkler-function

ActiveLibrary[Database &amp; ORM](/categories/database)

fza/mysql-doctrine-jaro-winkler-function
========================================

Provides the `JARO\_WINKLER\_SIMILARITY()` MySQL function for Doctrine2.

v0.1(11y ago)128883MITPHP

Since Mar 19Pushed 11y ago2 watchersCompare

[ Source](https://github.com/fza/mysql-doctrine-jaro-winkler-function)[ Packagist](https://packagist.org/packages/fza/mysql-doctrine-jaro-winkler-function)[ RSS](/packages/fza-mysql-doctrine-jaro-winkler-function/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Jaro-Winkler distance function for Doctrine and MySQL
=====================================================

[](#jaro-winkler-distance-function-for-doctrine-and-mysql)

A tiny Doctrine extension for the [Jaro-Winkler distance](http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance) algorithm to be used directly in DQL. The `JARO_WINKLER_SIMILARITY(s1, s2)` function returns a float between 0 and 1, where 0 means there's no similarity at all and 1 indicates an exact match.

Just for reference, there are plenty of alternative/additional algorithms to compute phonetic similarity. This is by all means not a complete list:

- [Damerau-Levenshtein distance](http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance)
- [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) (there is a [Doctrine extension](https://github.com/fza/mysql-doctrine-levenshtein-function) available as well)
- [Soundex](http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance)
- [Metaphone](http://en.wikipedia.org/wiki/Metaphone)

Define MySQL function
---------------------

[](#define-mysql-function)

- [Source](https://androidaddicted.wordpress.com/2010/06/01/jaro-winkler-sql-code/)

Execute the following commands to define the `JARO_WINKLER_SIMILARITY` function in the database. This needs to be done before you can use the function in any query.

```
DELIMITER $$

CREATE DEFINER =`root`@`localhost` FUNCTION `jaro_winkler_similarity`(
  in1 VARCHAR(255),
  in2 VARCHAR(255)
)
  RETURNS FLOAT
DETERMINISTIC
  BEGIN
#finestra:= search window, curString:= scanning cursor for the original string, curSub:= scanning cursor for the compared string
    DECLARE finestra, curString, curSub, maxSub, trasposizioni, prefixlen, maxPrefix INT;
    DECLARE char1, char2 CHAR(1);
    DECLARE common1, common2, old1, old2 VARCHAR(255);
    DECLARE trovato BOOLEAN;
    DECLARE returnValue, jaro FLOAT;
    SET maxPrefix = 6;
#from the original jaro - winkler algorithm
    SET common1 = "";
    SET common2 = "";
    SET finestra = (length(in1) + length(in2) - abs(length(in1) - length(in2))) DIV 4
                   + ((length(in1) + length(in2) - abs(length(in1) - length(in2))) / 2) MOD 2;
    SET old1 = in1;
    SET old2 = in2;

#calculating common letters vectors
    SET curString = 1;
    WHILE curString setParameter('nameQuery', 'michael');
$query->setParameter('minSimilarity', 0.5)
$matchingUsers = $query->getResult();
```

License
-------

[](#license)

Copyright (c) 2015 [Felix Zandanel](http://felix.zandanel.me/)
Licensed under the MIT license.

See LICENSE for more info.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4078d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/27446c4ce98055d35b8f113d4f6ca921003611fd7f223ca1c53b4ce10d023cd6?d=identicon)[fza](/maintainers/fza)

---

Top Contributors

[![fza](https://avatars.githubusercontent.com/u/578502?v=4)](https://github.com/fza "fza (1 commits)")

---

Tags

mysqldoctrinefunctionsimilarityjaro winkler

### Embed Badge

![Health badge](/badges/fza-mysql-doctrine-jaro-winkler-function/health.svg)

```
[![Health](https://phpackages.com/badges/fza-mysql-doctrine-jaro-winkler-function/health.svg)](https://phpackages.com/packages/fza-mysql-doctrine-jaro-winkler-function)
```

###  Alternatives

[oro/doctrine-extensions

Doctrine Extensions for MySQL and PostgreSQL.

34411.8M19](/packages/oro-doctrine-extensions)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[fza/mysql-doctrine-levenshtein-function

Provides the `LEVENSHTEIN()` and `LEVENSHTEIN\_RATIO()` MySQL functions for Doctrine2.

47115.8k1](/packages/fza-mysql-doctrine-levenshtein-function)[mapado/mysql-doctrine-functions

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE\_FORMAT()...

44271.5k1](/packages/mapado-mysql-doctrine-functions)[okapon/doctrine-set-type-bundle

Provides support of MySQL SET type for Doctrine2 in Symfony2 applications.

11159.0k](/packages/okapon-doctrine-set-type-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
