From 7b24f728709f73eee6f5cc9c87e7561caef2b746 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 1 May 2014 15:19:24 +0200 Subject: [PATCH] give slight preference to full-word matches when reranking fixes https://trac.openstreetmap.org/ticket/5094 --- lib/Geocode.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Geocode.php b/lib/Geocode.php index cc846f54..19fad13d 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -1566,7 +1566,7 @@ } $aClassType = getClassTypesWithImportance(); - $aRecheckWords = preg_split('/\b/u',$sQuery); + $aRecheckWords = preg_split('/\b[\s,\\-]*/u',$sQuery); foreach($aRecheckWords as $i => $sWord) { if (!$sWord) unset($aRecheckWords[$i]); @@ -1727,7 +1727,11 @@ $sAddress = $aResult['langaddress']; foreach($aRecheckWords as $i => $sWord) { - if (stripos($sAddress, $sWord)!==false) $iCountWords++; + if (stripos($sAddress, $sWord)!==false) + { + $iCountWords++; + if (preg_match("/(^|,)\s*$sWord\s*(,|$)/", $sAddress)) $iCountWords += 0.1; + } } $aResult['importance'] = $aResult['importance'] + ($iCountWords*0.1); // 0.1 is a completely arbitrary number but something in the range 0.1 to 0.5 would seem right -- 2.39.5