]> git.openstreetmap.org Git - nominatim.git/commitdiff
give slight preference to full-word matches when reranking
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 1 May 2014 13:19:24 +0000 (15:19 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 1 May 2014 13:19:24 +0000 (15:19 +0200)
fixes https://trac.openstreetmap.org/ticket/5094

lib/Geocode.php

index cc846f54d1896293143c3a5a452ca70c7229549b..19fad13d26795bacf6c67d753d41da5c0e3b538b 100644 (file)
                        }
 
                        $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]);
                                $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