mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-12-26 14:36:23 +03:00
Merge pull request #2373 from lonvia/tweak-search-cost
Further tweaking of search cost
This commit is contained in:
commit
c9984669a7
@ -348,8 +348,6 @@ class Geocode
|
|||||||
foreach ($oValidTokens->get(' '.$sToken) as $oSearchTerm) {
|
foreach ($oValidTokens->get(' '.$sToken) as $oSearchTerm) {
|
||||||
$aNewSearches = $oCurrentSearch->extendWithFullTerm(
|
$aNewSearches = $oCurrentSearch->extendWithFullTerm(
|
||||||
$oSearchTerm,
|
$oSearchTerm,
|
||||||
$oValidTokens->contains($sToken)
|
|
||||||
&& strpos($sToken, ' ') === false,
|
|
||||||
$sPhraseType,
|
$sPhraseType,
|
||||||
$iToken == 0 && $iPhrase == 0,
|
$iToken == 0 && $iPhrase == 0,
|
||||||
$iPhrase == 0,
|
$iPhrase == 0,
|
||||||
|
@ -153,8 +153,6 @@ class SearchDescription
|
|||||||
* Derive new searches by adding a full term to the existing search.
|
* Derive new searches by adding a full term to the existing search.
|
||||||
*
|
*
|
||||||
* @param object $oSearchTerm Description of the token.
|
* @param object $oSearchTerm Description of the token.
|
||||||
* @param bool $bHasPartial True if there are also tokens of partial terms
|
|
||||||
* with the same name.
|
|
||||||
* @param string $sPhraseType Type of phrase the token is contained in.
|
* @param string $sPhraseType Type of phrase the token is contained in.
|
||||||
* @param bool $bFirstToken True if the token is at the beginning of the
|
* @param bool $bFirstToken True if the token is at the beginning of the
|
||||||
* query.
|
* query.
|
||||||
@ -164,7 +162,7 @@ class SearchDescription
|
|||||||
*
|
*
|
||||||
* @return SearchDescription[] List of derived search descriptions.
|
* @return SearchDescription[] List of derived search descriptions.
|
||||||
*/
|
*/
|
||||||
public function extendWithFullTerm($oSearchTerm, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken)
|
public function extendWithFullTerm($oSearchTerm, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken)
|
||||||
{
|
{
|
||||||
$aNewSearches = array();
|
$aNewSearches = array();
|
||||||
|
|
||||||
@ -218,30 +216,33 @@ class SearchDescription
|
|||||||
&& is_a($oSearchTerm, '\Nominatim\Token\HouseNumber')
|
&& is_a($oSearchTerm, '\Nominatim\Token\HouseNumber')
|
||||||
) {
|
) {
|
||||||
if (!$this->sHouseNumber && $this->iOperator != Operator::POSTCODE) {
|
if (!$this->sHouseNumber && $this->iOperator != Operator::POSTCODE) {
|
||||||
$oSearch = clone $this;
|
|
||||||
$oSearch->iSearchRank++;
|
|
||||||
$oSearch->iNamePhrase = -1;
|
|
||||||
$oSearch->sHouseNumber = $oSearchTerm->sToken;
|
|
||||||
if ($this->iOperator != Operator::NONE) {
|
|
||||||
$oSearch->iSearchRank++;
|
|
||||||
}
|
|
||||||
// sanity check: if the housenumber is not mainly made
|
// sanity check: if the housenumber is not mainly made
|
||||||
// up of numbers, add a penalty
|
// up of numbers, add a penalty
|
||||||
if (preg_match('/\\d/', $oSearch->sHouseNumber) === 0
|
$iSearchCost = 1;
|
||||||
|| preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) {
|
if (preg_match('/\\d/', $oSearchTerm->sToken) === 0
|
||||||
$oSearch->iSearchRank++;
|
|| preg_match_all('/[^0-9]/', $oSearchTerm->sToken, $aMatches) > 2) {
|
||||||
|
$iSearchCost++;
|
||||||
|
}
|
||||||
|
if ($this->iOperator != Operator::NONE) {
|
||||||
|
$iSearchCost++;
|
||||||
}
|
}
|
||||||
if (empty($oSearchTerm->iId)) {
|
if (empty($oSearchTerm->iId)) {
|
||||||
$oSearch->iSearchRank++;
|
$iSearchCost++;
|
||||||
}
|
}
|
||||||
// also must not appear in the middle of the address
|
// also must not appear in the middle of the address
|
||||||
if (!empty($this->aAddress)
|
if (!empty($this->aAddress)
|
||||||
|| (!empty($this->aAddressNonSearch))
|
|| (!empty($this->aAddressNonSearch))
|
||||||
|| $this->sPostcode
|
|| $this->sPostcode
|
||||||
) {
|
) {
|
||||||
$oSearch->iSearchRank++;
|
$iSearchCost++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oSearch = clone $this;
|
||||||
|
$oSearch->iSearchRank += $iSearchCost;
|
||||||
|
$oSearch->iNamePhrase = -1;
|
||||||
|
$oSearch->sHouseNumber = $oSearchTerm->sToken;
|
||||||
$aNewSearches[] = $oSearch;
|
$aNewSearches[] = $oSearch;
|
||||||
|
|
||||||
// Housenumbers may appear in the name when the place has its own
|
// Housenumbers may appear in the name when the place has its own
|
||||||
// address terms.
|
// address terms.
|
||||||
if ($oSearchTerm->iId !== null
|
if ($oSearchTerm->iId !== null
|
||||||
@ -249,7 +250,7 @@ class SearchDescription
|
|||||||
&& empty($this->aAddress)
|
&& empty($this->aAddress)
|
||||||
) {
|
) {
|
||||||
$oSearch = clone $this;
|
$oSearch = clone $this;
|
||||||
$oSearch->iSearchRank++;
|
$oSearch->iSearchRank += $iSearchCost;
|
||||||
$oSearch->aAddress = $this->aName;
|
$oSearch->aAddress = $this->aName;
|
||||||
$oSearch->bRareName = false;
|
$oSearch->bRareName = false;
|
||||||
$oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId);
|
$oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId);
|
||||||
@ -295,10 +296,10 @@ class SearchDescription
|
|||||||
// the first phrase. In unstructured search it may be in a later
|
// the first phrase. In unstructured search it may be in a later
|
||||||
// phrase when the first phrase is a house number.
|
// phrase when the first phrase is a house number.
|
||||||
if (!empty($this->aName) || !($bFirstPhrase || $sPhraseType == '')) {
|
if (!empty($this->aName) || !($bFirstPhrase || $sPhraseType == '')) {
|
||||||
if (($sPhraseType == '' || !$bFirstPhrase) && !$bHasPartial) {
|
if (($sPhraseType == '' || !$bFirstPhrase) && $oSearchTerm->iTermCount > 1) {
|
||||||
$oSearch = clone $this;
|
$oSearch = clone $this;
|
||||||
$oSearch->iNamePhrase = -1;
|
$oSearch->iNamePhrase = -1;
|
||||||
$oSearch->iSearchRank += 3 * $oSearchTerm->iTermCount;
|
$oSearch->iSearchRank += 1;
|
||||||
$oSearch->aAddress[$iWordID] = $iWordID;
|
$oSearch->aAddress[$iWordID] = $iWordID;
|
||||||
$aNewSearches[] = $oSearch;
|
$aNewSearches[] = $oSearch;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user