]> git.openstreetmap.org Git - nominatim.git/blob - lib/Result.php
Merge pull request #986 from mtmail/php-replace-sizeof
[nominatim.git] / lib / Result.php
1 <?php
2
3 namespace Nominatim;
4
5 /**
6  * A single result of a search operation or a reverse lookup.
7  *
8  * This object only contains the id of the result. It does not yet
9  * have any details needed to format the output document.
10  */
11 class Result
12 {
13     const TABLE_PLACEX = 0;
14     const TABLE_POSTCODE = 1;
15     const TABLE_OSMLINE = 2;
16     const TABLE_AUX = 3;
17     const TABLE_TIGER = 4;
18
19     /// Database table that contains the result.
20     public $iTable;
21     /// Id of the result.
22     public $iId;
23     /// House number (only for interpolation results).
24     public $iHouseNumber = -1;
25     /// Number of exact matches in address (address searches only).
26     public $iExactMatches = 0;
27     /// Subranking within the results (the higher the worse).
28     public $iResultRank = 0;
29
30
31     public function __construct($sId, $iTable = Result::TABLE_PLACEX)
32     {
33         $this->iTable = $iTable;
34         $this->iId = (int) $sId;
35     }
36
37     public static function joinIdsByTable($aResults, $iTable)
38     {
39         return join(',', array_keys(array_filter(
40             $aResults,
41             function ($aValue) use ($iTable) {
42                 return $aValue->iTable == $iTable;
43             }
44         )));
45     }
46     public static function sqlHouseNumberTable($aResults, $iTable)
47     {
48         $sHousenumbers = '';
49         $sSep = '';
50         foreach ($aResults as $oResult) {
51             if ($oResult->iTable == $iTable) {
52                 $sHousenumbers .= $sSep.'('.$oResult->iId.',';
53                 $sHousenumbers .= $oResult->iHouseNumber.')';
54                 $sSep = ',';
55             }
56         }
57
58         return $sHousenumbers;
59     }
60 }