6 * A single result of a search operation or a reverse lookup.
8 * This object only contains the id of the result. It does not yet
9 * have any details needed to format the output document.
13 const TABLE_PLACEX = 0;
14 const TABLE_POSTCODE = 1;
15 const TABLE_OSMLINE = 2;
16 const TABLE_TIGER = 3;
18 /// Database table that contains the result.
22 /// House number (only for interpolation results).
23 public $iHouseNumber = -1;
24 /// Number of exact matches in address (address searches only).
25 public $iExactMatches = 0;
26 /// Subranking within the results (the higher the worse).
27 public $iResultRank = 0;
28 /// Address rank of the result.
31 public function debugInfo()
34 'Table' => $this->iTable,
36 'House number' => $this->iHouseNumber,
37 'Exact Matches' => $this->iExactMatches,
38 'Result rank' => $this->iResultRank
43 public function __construct($sId, $iTable = Result::TABLE_PLACEX)
45 $this->iTable = $iTable;
46 $this->iId = (int) $sId;
49 public static function joinIdsByTable($aResults, $iTable)
51 return join(',', array_keys(array_filter(
53 function ($aValue) use ($iTable) {
54 return $aValue->iTable == $iTable;
59 public static function joinIdsByTableMinRank($aResults, $iTable, $iMinAddressRank)
61 return join(',', array_keys(array_filter(
63 function ($aValue) use ($iTable, $iMinAddressRank) {
64 return $aValue->iTable == $iTable && $aValue->iAddressRank >= $iMinAddressRank;
69 public static function joinIdsByTableMaxRank($aResults, $iTable, $iMaxAddressRank)
71 return join(',', array_keys(array_filter(
73 function ($aValue) use ($iTable, $iMaxAddressRank) {
74 return $aValue->iTable == $iTable && $aValue->iAddressRank <= $iMaxAddressRank;
79 public static function sqlHouseNumberTable($aResults, $iTable)
83 foreach ($aResults as $oResult) {
84 if ($oResult->iTable == $iTable) {
85 $sHousenumbers .= $sSep.'('.$oResult->iId.',';
86 $sHousenumbers .= $oResult->iHouseNumber.')';
91 return $sHousenumbers;
95 * Split a result array into highest ranked result and the rest
97 * @param object[] $aResults List of results to split.
101 public static function splitResults($aResults)
107 foreach ($aResults as $oRes) {
108 if ($oRes->iResultRank < $iMinRank) {
110 $aHead = array($oRes->iId => $oRes);
111 $iMinRank = $oRes->iResultRank;
112 } elseif ($oRes->iResultRank == $iMinRank) {
113 $aHead[$oRes->iId] = $oRes;
115 $aTail[$oRes->iId] = $oRes;
119 return array('head' => $aHead, 'tail' => $aTail);