]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #2074 from lonvia/add-housenumber-to-unknown-places
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 25 Nov 2020 15:57:09 +0000 (16:57 +0100)
committerGitHub <noreply@github.com>
Wed, 25 Nov 2020 15:57:09 +0000 (16:57 +0100)
Improve finding addresses that have their own search_name entry because of unknown addr:* parts

1  2 
lib/SearchDescription.php

index 94ba87ff76480e3e237010e0b7005f5fa835034b,d8c541dbc8f8514d04a5f297d5681c4fb6e8ab54..1e1955c249a7e8a498a9c1d92d4bc08991fbf6b1
@@@ -21,6 -21,8 +21,6 @@@ class SearchDescriptio
      private $bRareName = false;
      /// List of word ids making up the address of the object.
      private $aAddress = array();
 -    /// Subset of word ids of full words making up the address.
 -    private $aFullNameAddress = array();
      /// List of word ids that appear in the name but should be ignored.
      private $aNameNonSearch = array();
      /// List of word ids that appear in the address but should be ignored.
                  ) {
                      $oSearch = clone $this;
                      $oSearch->iSearchRank++;
 +                    if (strlen($oSearchTerm->sPostcode) < 4) {
 +                        $oSearch->iSearchRank += 4 - strlen($oSearchTerm->sPostcode);
 +                    }
                      $oSearch->sPostcode = $oSearchTerm->sPostcode;
                      $aNewSearches[] = $oSearch;
                  }
                      $oSearch->iSearchRank++;
                  }
                  $aNewSearches[] = $oSearch;
+                 // Housenumbers may appear in the name when the place has its own
+                 // address terms.
+                 if ($oSearchTerm->iId !== null
+                     && ($this->iNamePhrase >= 0 || empty($this->aName))
+                     && empty($this->aAddress)
+                    ) {
+                     $oSearch = clone $this;
+                     $oSearch->iSearchRank++;
+                     $oSearch->aAddress = $this->aName;
+                     $oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId);
+                     $aNewSearches[] = $oSearch;
+                 }
              }
          } elseif ($sPhraseType == ''
                    && is_a($oSearchTerm, '\Nominatim\Token\SpecialTerm')
              if (!empty($this->aName) || !($bFirstPhrase || $sPhraseType == '')) {
                  if (($sPhraseType == '' || !$bFirstPhrase) && !$bHasPartial) {
                      $oSearch = clone $this;
 -                    $oSearch->iSearchRank += 2;
 +                    $oSearch->iSearchRank += 3 * $oSearchTerm->iTermCount;
                      $oSearch->aAddress[$iWordID] = $iWordID;
                      $aNewSearches[] = $oSearch;
 -                } else {
 -                    $this->aFullNameAddress[$iWordID] = $iWordID;
                  }
              } else {
                  $oSearch = clone $this;
          ) {
              if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) {
                  $oSearch = clone $this;
 -                $oSearch->iSearchRank += 2;
 +                $oSearch->iSearchRank += $oSearchTerm->iTermCount;
 +                if (empty($this->aName)) {
 +                    $oSearch->iSearchRank++;
 +                }
 +                if (preg_match('#^[0-9]+$#', $sToken)) {
 +                    $oSearch->iSearchRank++;
 +                }
                  $oSearch->aAddress[$iWordID] = $iWordID;
                  $aNewSearches[] = $oSearch;
              } else {
                  $oSearch = clone $this;
                  $oSearch->iSearchRank++;
                  $oSearch->aAddressNonSearch[$iWordID] = $iWordID;
 -                if (preg_match('#^[0-9]+$#', $sToken)) {
 -                    $oSearch->iSearchRank += 2;
 -                }
                  if (!empty($aFullTokens)) {
                      $oSearch->iSearchRank++;
                  }
                  foreach ($aFullTokens as $oSearchTermToken) {
                      if (is_a($oSearchTermToken, '\Nominatim\Token\Word')) {
                          $oSearch = clone $this;
 -                        $oSearch->iSearchRank++;
 +                        $oSearch->iSearchRank += 3;
                          $oSearch->aAddress[$oSearchTermToken->iId]
                              = $oSearchTermToken->iId;
                          $aNewSearches[] = $oSearch;
          $sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid');
          $aOrder[] = "$sImportanceSQL DESC";
  
 -        if (!empty($this->aFullNameAddress)) {
 +        $aFullNameAddress = $this->oContext->getFullNameTerms();
 +        if (!empty($aFullNameAddress)) {
              $sExactMatchSQL = ' ( ';
              $sExactMatchSQL .= ' SELECT count(*) FROM ( ';
 -            $sExactMatchSQL .= '  SELECT unnest('.$oDB->getArraySQL($this->aFullNameAddress).')';
 +            $sExactMatchSQL .= '  SELECT unnest('.$oDB->getArraySQL($aFullNameAddress).')';
              $sExactMatchSQL .= '    INTERSECT ';
              $sExactMatchSQL .= '  SELECT unnest(nameaddress_vector)';
              $sExactMatchSQL .= ' ) s';