]> git.openstreetmap.org Git - nominatim.git/commitdiff
order search results by existance of housenumbers
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 2 Feb 2015 06:41:28 +0000 (07:41 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 2 Feb 2015 06:41:28 +0000 (07:41 +0100)
When searching for an address with housenumber, include the house
number lookup already when searching in search_name so that we do
not cut away relevant results in cases where there are too many
street pieces.

lib/Geocode.php

index 202917a25dedfe87d5dd011422fa50226ba1fd49..2fa170a6d5f8bfc84f47d8946b97357d825e0a9c 100644 (file)
                                                                                        // sanity check: if the housenumber is not mainly made
                                                                                        // up of numbers, add a penalty
                                                                                        if (preg_match_all("/[^0-9]/", $sToken, $aMatches) > 2) $aSearch['iSearchRank']++;
                                                                                        // sanity check: if the housenumber is not mainly made
                                                                                        // up of numbers, add a penalty
                                                                                        if (preg_match_all("/[^0-9]/", $sToken, $aMatches) > 2) $aSearch['iSearchRank']++;
+                                                                                       // also housenumbers should appear in the first or second phrase
+                                                                                       if ($iPhrase > 1) $aSearch['iSearchRank'] += 1;
                                                                                        if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        /*
                                                                                        // Fall back to not searching for this item (better than nothing)
                                                                                        if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        /*
                                                                                        // Fall back to not searching for this item (better than nothing)
                                                        $aTerms = array();
                                                        $aOrder = array();
 
                                                        $aTerms = array();
                                                        $aOrder = array();
 
+                                                       if ($aSearch['sHouseNumber'])
+                                                       {
+                                                               $sHouseNumberRegex = '\\\\m'.$aSearch['sHouseNumber'].'\\\\M';
+                                                               $aOrder[] = "exists(select place_id from placex where parent_place_id = search_name.place_id and transliteration(housenumber) ~* E'".$sHouseNumberRegex."' limit 1) desc";
+                                                       }
+
                                                        // TODO: filter out the pointless search terms (2 letter name tokens and less)
                                                        // they might be right - but they are just too darned expensive to run
                                                        if (sizeof($aSearch['aName'])) $aTerms[] = "name_vector @> ARRAY[".join($aSearch['aName'],",")."]";
                                                        // TODO: filter out the pointless search terms (2 letter name tokens and less)
                                                        // they might be right - but they are just too darned expensive to run
                                                        if (sizeof($aSearch['aName'])) $aTerms[] = "name_vector @> ARRAY[".join($aSearch['aName'],",")."]";
                                                                $sSQL .= " where ".join(' and ',$aTerms);
                                                                $sSQL .= " order by ".join(', ',$aOrder);
                                                                if ($aSearch['sHouseNumber'] || $aSearch['sClass'])
                                                                $sSQL .= " where ".join(' and ',$aTerms);
                                                                $sSQL .= " order by ".join(', ',$aOrder);
                                                                if ($aSearch['sHouseNumber'] || $aSearch['sClass'])
-                                                                       $sSQL .= " limit 50";
+                                                                       $sSQL .= " limit 20";
                                                                elseif (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && $aSearch['sClass'])
                                                                        $sSQL .= " limit 1";
                                                                else
                                                                elseif (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && $aSearch['sClass'])
                                                                        $sSQL .= " limit 1";
                                                                else