|
4 | 4 |
|
5 | 5 | class ListDiff extends HtmlDiff |
6 | 6 | { |
| 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 | + |
7 | 13 | /** @var array */ |
8 | 14 | protected $listWords = array(); |
9 | 15 |
|
@@ -226,22 +232,27 @@ function ($v) use ($percent) { |
226 | 232 | ); |
227 | 233 |
|
228 | 234 | 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)) { |
241 | 242 | $highestMatch = $percent; |
242 | 243 | $highestMatchKey = $key; |
243 | 244 | $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 | + } |
245 | 256 | } |
246 | 257 | } |
247 | 258 | } |
|
0 commit comments