Update fuzz.php
Set the strings in lower case to avoid missing results because of the case.
This commit is contained in:
parent
55d3b162bf
commit
64612b85f9
1 changed files with 41 additions and 6 deletions
43
bl-plugins/search/vendors/fuzz.php
vendored
43
bl-plugins/search/vendors/fuzz.php
vendored
|
@ -34,6 +34,7 @@ class Fuzz
|
||||||
*/
|
*/
|
||||||
public function __construct($source, $maxResults, $searchMode, $useLCS)
|
public function __construct($source, $maxResults, $searchMode, $useLCS)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->_source = $source;
|
$this->_source = $source;
|
||||||
$this->_sourceLen = count($source);
|
$this->_sourceLen = count($source);
|
||||||
$this->_maxResults = max($maxResults, 1);
|
$this->_maxResults = max($maxResults, 1);
|
||||||
|
@ -61,13 +62,16 @@ class Fuzz
|
||||||
$results = [];
|
$results = [];
|
||||||
$scores = [];
|
$scores = [];
|
||||||
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$search = strtolower($search);
|
||||||
|
|
||||||
// Nullify these parameters if they are irrelevant to searchMode
|
// Nullify these parameters if they are irrelevant to searchMode
|
||||||
if (!$this->_useLCS) $minLCS = null;
|
if (!$this->_useLCS) $minLCS = null;
|
||||||
if ($this->_searchMode != 0) $maxDistance = null;
|
if ($this->_searchMode != 0) $maxDistance = null;
|
||||||
|
|
||||||
// Cycle through result pool
|
// Cycle through result pool
|
||||||
//for ($i = 0; $i < $this->_sourceLen; $i++) {
|
//for ($i = 0; $i < $this->_sourceLen; $i++) {
|
||||||
foreach ($this->_source as $pageKey => $data) {
|
foreach ($this->_source as $pageKey => $data) {
|
||||||
$allLev = [];
|
$allLev = [];
|
||||||
$allJaros = [];
|
$allJaros = [];
|
||||||
$allLCSs = [];
|
$allLCSs = [];
|
||||||
|
@ -125,6 +129,11 @@ class Fuzz
|
||||||
{
|
{
|
||||||
$suffix = [];
|
$suffix = [];
|
||||||
$result = 0;
|
$result = 0;
|
||||||
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$source = strtolower($source);
|
||||||
|
$target = strtolower($target);
|
||||||
|
|
||||||
$n = mb_strlen($source, CHARSET);
|
$n = mb_strlen($source, CHARSET);
|
||||||
$m = mb_strlen($target, CHARSET);
|
$m = mb_strlen($target, CHARSET);
|
||||||
|
|
||||||
|
@ -158,6 +167,10 @@ class Fuzz
|
||||||
$n = mb_strlen($source, CHARSET);
|
$n = mb_strlen($source, CHARSET);
|
||||||
$m = mb_strlen($target, CHARSET);
|
$m = mb_strlen($target, CHARSET);
|
||||||
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$source = strtolower($source);
|
||||||
|
$target = strtolower($target);
|
||||||
|
|
||||||
if ($n === 0) {
|
if ($n === 0) {
|
||||||
return $m;
|
return $m;
|
||||||
} elseif ($m === 0) {
|
} elseif ($m === 0) {
|
||||||
|
@ -205,8 +218,12 @@ class Fuzz
|
||||||
*/
|
*/
|
||||||
public function getJaroWinkler($first, $second)
|
public function getJaroWinkler($first, $second)
|
||||||
{
|
{
|
||||||
$shorter = '';
|
$shorter;
|
||||||
$longer = '';
|
$longer;
|
||||||
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$first = strtolower($first);
|
||||||
|
$second = strtolower($second);
|
||||||
|
|
||||||
if (mb_strlen($first, CHARSET) > mb_strlen($second, CHARSET)) {
|
if (mb_strlen($first, CHARSET) > mb_strlen($second, CHARSET)) {
|
||||||
$longer = mb_strtolower($first, CHARSET);
|
$longer = mb_strtolower($first, CHARSET);
|
||||||
|
@ -255,6 +272,11 @@ class Fuzz
|
||||||
{
|
{
|
||||||
$common = '';
|
$common = '';
|
||||||
$copy = $second;
|
$copy = $second;
|
||||||
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$first = strtolower($first);
|
||||||
|
$second = strtolower($second);
|
||||||
|
|
||||||
$firstLen = mb_strlen($first, CHARSET);
|
$firstLen = mb_strlen($first, CHARSET);
|
||||||
$secondLen = mb_strlen($second, CHARSET);
|
$secondLen = mb_strlen($second, CHARSET);
|
||||||
|
|
||||||
|
@ -285,7 +307,12 @@ class Fuzz
|
||||||
private function _getTranspositions($first, $second)
|
private function _getTranspositions($first, $second)
|
||||||
{
|
{
|
||||||
$trans = 0;
|
$trans = 0;
|
||||||
$firstLen = mb_strlen($first, CHARSET);
|
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$first = strtolower($first);
|
||||||
|
$second = strtolower($second);
|
||||||
|
|
||||||
|
$firstLen = mb_strlen($first, CHARSET);
|
||||||
|
|
||||||
for ($i = 0; $i < $firstLen; $i++) {
|
for ($i = 0; $i < $firstLen; $i++) {
|
||||||
if ($first[$i] != $second[$i]) {
|
if ($first[$i] != $second[$i]) {
|
||||||
|
@ -307,6 +334,10 @@ class Fuzz
|
||||||
*/
|
*/
|
||||||
private function _getPrefix($first, $second)
|
private function _getPrefix($first, $second)
|
||||||
{
|
{
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$first = strtolower($first);
|
||||||
|
$second = strtolower($second);
|
||||||
|
|
||||||
if (mb_strlen($first, CHARSET) == 0 || mb_strlen($second, CHARSET) == 0) {
|
if (mb_strlen($first, CHARSET) == 0 || mb_strlen($second, CHARSET) == 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -331,6 +362,10 @@ class Fuzz
|
||||||
*/
|
*/
|
||||||
private function _getDiffIndex($first, $second)
|
private function _getDiffIndex($first, $second)
|
||||||
{
|
{
|
||||||
|
// put the text in lower case to avoid missing a result because of the case
|
||||||
|
$first = strtolower($first);
|
||||||
|
$second = strtolower($second);
|
||||||
|
|
||||||
if ($first == $second) {
|
if ($first == $second) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue