Skip to content

Commit 3271637

Browse files
committed
Added a threshold as the minimum percentage a list item can have before being considered a match.
1 parent 150bfb6 commit 3271637

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/Caxy/HtmlDiff/ListDiff.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
class ListDiff extends HtmlDiff
66
{
7+
/**
8+
* This is the minimum percentage a list item can match its counterpart in order to be considered a match.
9+
* @var integer
10+
*/
11+
protected static $listMatchThreshold = 50;
12+
713
/** @var array */
814
protected $listWords = array();
915

@@ -226,22 +232,27 @@ function ($v) use ($percent) {
226232
);
227233

228234
arsort($thisBestMatches);
229-
230-
// If no greater amounts, use this one.
231-
if (!count($thisBestMatches)) {
232-
$highestMatch = $percent;
233-
$highestMatchKey = $key;
234-
$takenItemKey = $item;
235-
break;
236-
}
237-
238-
// Loop through, comparing only the items that have not already been added.
239-
foreach ($thisBestMatches as $k => $v) {
240-
if (in_array($k, $takenItems)) {
235+
236+
/**
237+
* If the list item does not meet the threshold, it will not be considered a match.
238+
*/
239+
if ($percent >= self::$listMatchThreshold) {
240+
// If no greater amounts, use this one.
241+
if (!count($thisBestMatches)) {
241242
$highestMatch = $percent;
242243
$highestMatchKey = $key;
243244
$takenItemKey = $item;
244-
break(2);
245+
break;
246+
}
247+
248+
// Loop through, comparing only the items that have not already been added.
249+
foreach ($thisBestMatches as $k => $v) {
250+
if (in_array($k, $takenItems)) {
251+
$highestMatch = $percent;
252+
$highestMatchKey = $key;
253+
$takenItemKey = $item;
254+
break(2);
255+
}
245256
}
246257
}
247258
}

0 commit comments

Comments
 (0)