3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 namespace Nominatim\Token;
14 * A standard word token.
18 /// Database word id, if applicable.
20 /// Number of appearances in the database.
21 private $iSearchNameCount;
22 /// Number of terms in the word.
25 public function __construct($iId, $iSearchNameCount, $iTermCount)
28 $this->iSearchNameCount = $iSearchNameCount;
29 $this->iTermCount = $iTermCount;
32 public function getId()
38 * Check if the token can be added to the given search.
39 * Derive new searches by adding this token to an existing search.
41 * @param object $oSearch Partial search description derived so far.
42 * @param object $oPosition Description of the token position within
45 * @return True if the token is compatible with the search configuration
48 public function isExtendable($oSearch, $oPosition)
50 return !$oPosition->isPhrase('country');
54 * Derive new searches by adding this token to an existing search.
56 * @param object $oSearch Partial search description derived so far.
57 * @param object $oPosition Description of the token position within
60 * @return SearchDescription[] List of derived search descriptions.
62 public function extendSearch($oSearch, $oPosition)
64 // Full words can only be a name if they appear at the beginning
65 // of the phrase. In structured search the name must forcably in
66 // the first phrase. In unstructured search it may be in a later
67 // phrase when the first phrase is a house number.
68 if ($oSearch->hasName()
69 || !($oPosition->isFirstPhrase() || $oPosition->isPhrase(''))
71 if ($this->iTermCount > 1
72 && ($oPosition->isPhrase('') || !$oPosition->isFirstPhrase())
74 $oNewSearch = $oSearch->clone(1);
75 $oNewSearch->addAddressToken($this->iId);
77 return array($oNewSearch);
79 } elseif (!$oSearch->hasName(true)) {
80 $oNewSearch = $oSearch->clone(1);
81 $oNewSearch->addNameToken(
83 CONST_Search_NameOnlySearchFrequencyThreshold
84 && $this->iSearchNameCount
85 < CONST_Search_NameOnlySearchFrequencyThreshold
88 return array($oNewSearch);
94 public function debugInfo()
100 'count' => $this->iSearchNameCount,
101 'terms' => $this->iTermCount
106 public function debugCode()