X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/75c631f08093d0cc7330d313bd3bb58cb2c1924b..86eeb4d2eddaa6c409f542169780f59dc31ffc1b:/lib-php/SearchDescription.php diff --git a/lib-php/SearchDescription.php b/lib-php/SearchDescription.php index ee8bbc0c..fa622e62 100644 --- a/lib-php/SearchDescription.php +++ b/lib-php/SearchDescription.php @@ -19,6 +19,8 @@ class SearchDescription private $aName = array(); /// True if the name is rare enough to force index use on name. private $bRareName = false; + /// True if the name requires to be accompanied by address terms. + private $bNameNeedsAddress = false; /// List of word ids making up the address of the object. private $aAddress = array(); /// List of word ids that appear in the name but should be ignored. @@ -113,6 +115,9 @@ class SearchDescription return false; } } + if ($this->bNameNeedsAddress && empty($this->aAddress)) { + return false; + } return true; } @@ -231,6 +236,7 @@ class SearchDescription { $this->aName[$iId] = $iId; $this->bRareName = $bRareName; + $this->bNameNeedsAddress = false; } /** @@ -240,11 +246,19 @@ class SearchDescription * @param integer iID ID of term to add. * @param bool bSearchable Term should be used to search for result * (i.e. term is not a stop word). + * @param bool bNeedsAddress True if the term is too unspecific to be used + * in a stand-alone search without an address + * to narrow down the search. * @param integer iPhraseNumber Index of phrase, where the partial term * appears. */ - public function addPartialNameToken($iId, $bSearchable, $iPhraseNumber) + public function addPartialNameToken($iId, $bSearchable, $bNeedsAddress, $iPhraseNumber) { + if (empty($this->aName)) { + $this->bNameNeedsAddress = $bNeedsAddress; + } else { + $this->bNameNeedsAddress |= $bNeedsAddress; + } if ($bSearchable) { $this->aName[$iId] = $iId; } else { @@ -310,6 +324,7 @@ class SearchDescription { $this->aAddress = array_merge($this->aAddress, $this->aName); $this->bRareName = false; + $this->bNameNeedsAddress = true; $this->aName = array($iId => $iId); $this->iNamePhrase = -1; }