]> git.openstreetmap.org Git - nominatim.git/blob - lib/Result.php
clean up docs for lookup call
[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     public function debugInfo()
31     {
32         return array(
33                 'Table' => $this->iTable,
34                 'ID' => $this->iId,
35                 'House number' => $this->iHouseNumber,
36                 'Exact Matches' => $this->iExactMatches,
37                 'Result rank' => $this->iResultRank
38                );
39     }
40
41
42     public function __construct($sId, $iTable = Result::TABLE_PLACEX)
43     {
44         $this->iTable = $iTable;
45         $this->iId = (int) $sId;
46     }
47
48     public static function joinIdsByTable($aResults, $iTable)
49     {
50         return join(',', array_keys(array_filter(
51             $aResults,
52             function ($aValue) use ($iTable) {
53                 return $aValue->iTable == $iTable;
54             }
55         )));
56     }
57     public static function sqlHouseNumberTable($aResults, $iTable)
58     {
59         $sHousenumbers = '';
60         $sSep = '';
61         foreach ($aResults as $oResult) {
62             if ($oResult->iTable == $iTable) {
63                 $sHousenumbers .= $sSep.'('.$oResult->iId.',';
64                 $sHousenumbers .= $oResult->iHouseNumber.')';
65                 $sSep = ',';
66             }
67         }
68
69         return $sHousenumbers;
70     }
71 }