]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/TokenCountry.php
only instantiate indexer once for replication
[nominatim.git] / lib-php / TokenCountry.php
1 <?php
2
3 namespace Nominatim\Token;
4
5 /**
6  * A country token.
7  */
8 class Country
9 {
10     /// Database word id, if available.
11     private $iId;
12     /// Two-letter country code (lower-cased).
13     private $sCountryCode;
14
15     public function __construct($iId, $sCountryCode)
16     {
17         $this->iId = $iId;
18         $this->sCountryCode = $sCountryCode;
19     }
20
21     public function getId()
22     {
23         return $this->iId;
24     }
25
26     /**
27      * Check if the token can be added to the given search.
28      * Derive new searches by adding this token to an existing search.
29      *
30      * @param object  $oSearch      Partial search description derived so far.
31      * @param object  $oPosition    Description of the token position within
32                                     the query.
33      *
34      * @return True if the token is compatible with the search configuration
35      *         given the position.
36      */
37     public function isExtendable($oSearch, $oPosition)
38     {
39         return !$oSearch->hasCountry()
40                && $oPosition->maybePhrase('country')
41                && $oSearch->getContext()->isCountryApplicable($this->sCountryCode);
42     }
43
44     /**
45      * Derive new searches by adding this token to an existing search.
46      *
47      * @param object  $oSearch      Partial search description derived so far.
48      * @param object  $oPosition    Description of the token position within
49                                     the query.
50      *
51      * @return SearchDescription[] List of derived search descriptions.
52      */
53     public function extendSearch($oSearch, $oPosition)
54     {
55         $oNewSearch = $oSearch->clone($oPosition->isLastToken() ? 1 : 6);
56         $oNewSearch->setCountry($this->sCountryCode);
57
58         return array($oNewSearch);
59     }
60
61     public function debugInfo()
62     {
63         return array(
64                 'ID' => $this->iId,
65                 'Type' => 'country',
66                 'Info' => $this->sCountryCode
67                );
68     }
69
70     public function debugCode()
71     {
72         return 'C';
73     }
74 }