@@ -22,180 +22,180 @@ |
||
| 22 | 22 | * @author Mark Prins |
| 23 | 23 | */ |
| 24 | 24 | class helper_plugin_spatialhelper_search extends DokuWiki_Plugin { |
| 25 | - /** |
|
| 26 | - * spatial index. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $spatial_idx = array(); |
|
| 31 | - /** |
|
| 32 | - * handle to the geoPHP plugin. |
|
| 33 | - */ |
|
| 34 | - protected $geophp; |
|
| 35 | - /** |
|
| 36 | - * Precision, Distance of Adjacent Cell in Meters. |
|
| 37 | - * |
|
| 38 | - * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance |
|
| 39 | - * |
|
| 40 | - * @var float |
|
| 41 | - */ |
|
| 42 | - private $precision = array( |
|
| 43 | - 5003530, |
|
| 44 | - 625441, |
|
| 45 | - 123264, |
|
| 46 | - 19545, |
|
| 47 | - 3803, |
|
| 48 | - 610, |
|
| 49 | - 118, |
|
| 50 | - 19, |
|
| 51 | - 3.7, |
|
| 52 | - 0.6 |
|
| 53 | - ); |
|
| 25 | + /** |
|
| 26 | + * spatial index. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $spatial_idx = array(); |
|
| 31 | + /** |
|
| 32 | + * handle to the geoPHP plugin. |
|
| 33 | + */ |
|
| 34 | + protected $geophp; |
|
| 35 | + /** |
|
| 36 | + * Precision, Distance of Adjacent Cell in Meters. |
|
| 37 | + * |
|
| 38 | + * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance |
|
| 39 | + * |
|
| 40 | + * @var float |
|
| 41 | + */ |
|
| 42 | + private $precision = array( |
|
| 43 | + 5003530, |
|
| 44 | + 625441, |
|
| 45 | + 123264, |
|
| 46 | + 19545, |
|
| 47 | + 3803, |
|
| 48 | + 610, |
|
| 49 | + 118, |
|
| 50 | + 19, |
|
| 51 | + 3.7, |
|
| 52 | + 0.6 |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * constructor; initialize/load spatial index. |
|
| 57 | - */ |
|
| 58 | - public function __construct() { |
|
| 59 | - // parent::__construct (); |
|
| 60 | - global $conf; |
|
| 55 | + /** |
|
| 56 | + * constructor; initialize/load spatial index. |
|
| 57 | + */ |
|
| 58 | + public function __construct() { |
|
| 59 | + // parent::__construct (); |
|
| 60 | + global $conf; |
|
| 61 | 61 | |
| 62 | - if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 63 | - $message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.'; |
|
| 64 | - msg($message, -1); |
|
| 65 | - } |
|
| 62 | + if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 63 | + $message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.'; |
|
| 64 | + msg($message, -1); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $idx_dir = $conf ['indexdir']; |
|
| 68 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
| 69 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 70 | - } |
|
| 67 | + $idx_dir = $conf ['indexdir']; |
|
| 68 | + if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
| 69 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false)); |
|
| 73 | - } |
|
| 72 | + $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false)); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Find locations based on the coordinate pair. |
|
| 77 | - * |
|
| 78 | - * @param float $lat |
|
| 79 | - * The y coordinate (or latitude) |
|
| 80 | - * @param float $lon |
|
| 81 | - * The x coordinate (or longitude) |
|
| 82 | - */ |
|
| 83 | - public function findNearbyLatLon(float $lat, float $lon): array { |
|
| 84 | - $geometry = new geoPHP\Geometry\Point($lon, $lat); |
|
| 85 | - return $this->findNearby($geometry->out('geohash'), $geometry); |
|
| 86 | - } |
|
| 75 | + /** |
|
| 76 | + * Find locations based on the coordinate pair. |
|
| 77 | + * |
|
| 78 | + * @param float $lat |
|
| 79 | + * The y coordinate (or latitude) |
|
| 80 | + * @param float $lon |
|
| 81 | + * The x coordinate (or longitude) |
|
| 82 | + */ |
|
| 83 | + public function findNearbyLatLon(float $lat, float $lon): array { |
|
| 84 | + $geometry = new geoPHP\Geometry\Point($lon, $lat); |
|
| 85 | + return $this->findNearby($geometry->out('geohash'), $geometry); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * finds nearby elements in the index based on the geohash. |
|
| 90 | - * returns a list of documents and the bunding box. |
|
| 91 | - * |
|
| 92 | - * @param string $geohash |
|
| 93 | - * @param geoPHP\Geometry\Point $p |
|
| 94 | - * optional point |
|
| 95 | - * @return array of ... |
|
| 96 | - */ |
|
| 97 | - public function findNearby(string $geohash, geoPHP\Geometry\Point $p = null): array { |
|
| 98 | - $_geohashClass = new geoPHP\Adapter\Geohash(); |
|
| 99 | - if(!$p) { |
|
| 100 | - $decodedPoint = $_geohashClass->read($geohash); |
|
| 101 | - } else { |
|
| 102 | - $decodedPoint = $p; |
|
| 103 | - } |
|
| 88 | + /** |
|
| 89 | + * finds nearby elements in the index based on the geohash. |
|
| 90 | + * returns a list of documents and the bunding box. |
|
| 91 | + * |
|
| 92 | + * @param string $geohash |
|
| 93 | + * @param geoPHP\Geometry\Point $p |
|
| 94 | + * optional point |
|
| 95 | + * @return array of ... |
|
| 96 | + */ |
|
| 97 | + public function findNearby(string $geohash, geoPHP\Geometry\Point $p = null): array { |
|
| 98 | + $_geohashClass = new geoPHP\Adapter\Geohash(); |
|
| 99 | + if(!$p) { |
|
| 100 | + $decodedPoint = $_geohashClass->read($geohash); |
|
| 101 | + } else { |
|
| 102 | + $decodedPoint = $p; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - // find adjacent blocks |
|
| 106 | - $adjacent = array(); |
|
| 107 | - $adjacent ['center'] = $geohash; |
|
| 108 | - $adjacent ['top'] = $_geohashClass->adjacent($adjacent ['center'], 'top'); |
|
| 109 | - $adjacent ['bottom'] = $_geohashClass->adjacent($adjacent ['center'], 'bottom'); |
|
| 110 | - $adjacent ['right'] = $_geohashClass->adjacent($adjacent ['center'], 'right'); |
|
| 111 | - $adjacent ['left'] = $_geohashClass->adjacent($adjacent ['center'], 'left'); |
|
| 112 | - $adjacent ['topleft'] = $_geohashClass->adjacent($adjacent ['left'], 'top'); |
|
| 113 | - $adjacent ['topright'] = $_geohashClass->adjacent($adjacent ['right'], 'top'); |
|
| 114 | - $adjacent ['bottomright'] = $_geohashClass->adjacent($adjacent ['right'], 'bottom'); |
|
| 115 | - $adjacent ['bottomleft'] = $_geohashClass->adjacent($adjacent ['left'], 'bottom'); |
|
| 116 | - dbglog($adjacent, "adjacent geo hashes:"); |
|
| 105 | + // find adjacent blocks |
|
| 106 | + $adjacent = array(); |
|
| 107 | + $adjacent ['center'] = $geohash; |
|
| 108 | + $adjacent ['top'] = $_geohashClass->adjacent($adjacent ['center'], 'top'); |
|
| 109 | + $adjacent ['bottom'] = $_geohashClass->adjacent($adjacent ['center'], 'bottom'); |
|
| 110 | + $adjacent ['right'] = $_geohashClass->adjacent($adjacent ['center'], 'right'); |
|
| 111 | + $adjacent ['left'] = $_geohashClass->adjacent($adjacent ['center'], 'left'); |
|
| 112 | + $adjacent ['topleft'] = $_geohashClass->adjacent($adjacent ['left'], 'top'); |
|
| 113 | + $adjacent ['topright'] = $_geohashClass->adjacent($adjacent ['right'], 'top'); |
|
| 114 | + $adjacent ['bottomright'] = $_geohashClass->adjacent($adjacent ['right'], 'bottom'); |
|
| 115 | + $adjacent ['bottomleft'] = $_geohashClass->adjacent($adjacent ['left'], 'bottom'); |
|
| 116 | + dbglog($adjacent, "adjacent geo hashes:"); |
|
| 117 | 117 | |
| 118 | - // find all the pages in the index that overlap with the adjacent hashes |
|
| 119 | - $docIds = array(); |
|
| 120 | - foreach($adjacent as $adjHash) { |
|
| 121 | - if(is_array($this->spatial_idx)) { |
|
| 122 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
| 123 | - if(strpos($_geohash, $adjHash) !== false) { |
|
| 124 | - // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
|
| 125 | - // if $adjHash similar to geohash |
|
| 126 | - $docIds = array_merge($docIds, $_docIds); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - $docIds = array_unique($docIds); |
|
| 132 | - dbglog($docIds, "found docIDs"); |
|
| 118 | + // find all the pages in the index that overlap with the adjacent hashes |
|
| 119 | + $docIds = array(); |
|
| 120 | + foreach($adjacent as $adjHash) { |
|
| 121 | + if(is_array($this->spatial_idx)) { |
|
| 122 | + foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
| 123 | + if(strpos($_geohash, $adjHash) !== false) { |
|
| 124 | + // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
|
| 125 | + // if $adjHash similar to geohash |
|
| 126 | + $docIds = array_merge($docIds, $_docIds); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + $docIds = array_unique($docIds); |
|
| 132 | + dbglog($docIds, "found docIDs"); |
|
| 133 | 133 | |
| 134 | - // create associative array of pages + calculate distance |
|
| 135 | - $pages = array(); |
|
| 136 | - $media = array(); |
|
| 137 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 134 | + // create associative array of pages + calculate distance |
|
| 135 | + $pages = array(); |
|
| 136 | + $media = array(); |
|
| 137 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 138 | 138 | |
| 139 | - foreach($docIds as $id) { |
|
| 140 | - if(strpos($id, 'media__', 0) === 0) { |
|
| 141 | - $id = substr($id, strlen('media__')); |
|
| 142 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 143 | - $point = $indexer->getCoordsFromExif($id); |
|
| 144 | - $line = new geoPHP\Geometry\LineString( |
|
| 145 | - [ |
|
| 146 | - $decodedPoint, |
|
| 147 | - $point |
|
| 148 | - ] |
|
| 149 | - ); |
|
| 150 | - $media [] = array( |
|
| 151 | - 'id' => $id, |
|
| 152 | - 'distance' => (int) ($line->greatCircleLength()), |
|
| 153 | - 'lat' => $point->y(), |
|
| 154 | - 'lon' => $point->x() |
|
| 155 | - // optionally add other meta such as tag, description... |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - } else { |
|
| 159 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 160 | - $geotags = p_get_metadata($id, 'geo'); |
|
| 161 | - $point = new geoPHP\Geometry\Point($geotags ['lon'], $geotags ['lat']); |
|
| 162 | - $line = new geoPHP\Geometry\LineString( |
|
| 163 | - [ |
|
| 164 | - $decodedPoint, |
|
| 165 | - $point |
|
| 166 | - ] |
|
| 167 | - ); |
|
| 168 | - $pages [] = array( |
|
| 169 | - 'id' => $id, |
|
| 170 | - 'distance' => (int) ($line->greatCircleLength()), |
|
| 171 | - 'description' => p_get_metadata($id, 'description')['abstract'], |
|
| 172 | - 'lat' => $geotags ['lat'], |
|
| 173 | - 'lon' => $geotags ['lon'] |
|
| 174 | - // optionally add other meta such as tag... |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 139 | + foreach($docIds as $id) { |
|
| 140 | + if(strpos($id, 'media__', 0) === 0) { |
|
| 141 | + $id = substr($id, strlen('media__')); |
|
| 142 | + if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 143 | + $point = $indexer->getCoordsFromExif($id); |
|
| 144 | + $line = new geoPHP\Geometry\LineString( |
|
| 145 | + [ |
|
| 146 | + $decodedPoint, |
|
| 147 | + $point |
|
| 148 | + ] |
|
| 149 | + ); |
|
| 150 | + $media [] = array( |
|
| 151 | + 'id' => $id, |
|
| 152 | + 'distance' => (int) ($line->greatCircleLength()), |
|
| 153 | + 'lat' => $point->y(), |
|
| 154 | + 'lon' => $point->x() |
|
| 155 | + // optionally add other meta such as tag, description... |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + } else { |
|
| 159 | + if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 160 | + $geotags = p_get_metadata($id, 'geo'); |
|
| 161 | + $point = new geoPHP\Geometry\Point($geotags ['lon'], $geotags ['lat']); |
|
| 162 | + $line = new geoPHP\Geometry\LineString( |
|
| 163 | + [ |
|
| 164 | + $decodedPoint, |
|
| 165 | + $point |
|
| 166 | + ] |
|
| 167 | + ); |
|
| 168 | + $pages [] = array( |
|
| 169 | + 'id' => $id, |
|
| 170 | + 'distance' => (int) ($line->greatCircleLength()), |
|
| 171 | + 'description' => p_get_metadata($id, 'description')['abstract'], |
|
| 172 | + 'lat' => $geotags ['lat'], |
|
| 173 | + 'lon' => $geotags ['lon'] |
|
| 174 | + // optionally add other meta such as tag... |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // sort all the pages/media using distance |
|
| 181 | - usort( |
|
| 182 | - $pages, static function ($a, $b) { |
|
| 183 | - return strnatcmp($a ['distance'], $b ['distance']); |
|
| 184 | - } |
|
| 185 | - ); |
|
| 186 | - usort( |
|
| 187 | - $media, static function ($a, $b) { |
|
| 188 | - return strnatcmp($a ['distance'], $b ['distance']); |
|
| 189 | - } |
|
| 190 | - ); |
|
| 180 | + // sort all the pages/media using distance |
|
| 181 | + usort( |
|
| 182 | + $pages, static function ($a, $b) { |
|
| 183 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
| 184 | + } |
|
| 185 | + ); |
|
| 186 | + usort( |
|
| 187 | + $media, static function ($a, $b) { |
|
| 188 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
| 189 | + } |
|
| 190 | + ); |
|
| 191 | 191 | |
| 192 | - return array( |
|
| 193 | - 'pages' => $pages, |
|
| 194 | - 'media' => $media, |
|
| 195 | - 'lat' => $decodedPoint->y(), |
|
| 196 | - 'lon' => $decodedPoint->x(), |
|
| 197 | - 'geohash' => $geohash, |
|
| 198 | - 'precision' => $this->precision [strlen($geohash)] |
|
| 199 | - ); |
|
| 200 | - } |
|
| 192 | + return array( |
|
| 193 | + 'pages' => $pages, |
|
| 194 | + 'media' => $media, |
|
| 195 | + 'lat' => $decodedPoint->y(), |
|
| 196 | + 'lon' => $decodedPoint->x(), |
|
| 197 | + 'geohash' => $geohash, |
|
| 198 | + 'precision' => $this->precision [strlen($geohash)] |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | // parent::__construct (); |
| 60 | 60 | global $conf; |
| 61 | 61 | |
| 62 | - if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 62 | + if (!$geophp = plugin_load('helper', 'geophp')) { |
|
| 63 | 63 | $message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.'; |
| 64 | 64 | msg($message, -1); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $idx_dir = $conf ['indexdir']; |
| 68 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
| 68 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
| 69 | 69 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function findNearby(string $geohash, geoPHP\Geometry\Point $p = null): array { |
| 98 | 98 | $_geohashClass = new geoPHP\Adapter\Geohash(); |
| 99 | - if(!$p) { |
|
| 99 | + if (!$p) { |
|
| 100 | 100 | $decodedPoint = $_geohashClass->read($geohash); |
| 101 | 101 | } else { |
| 102 | 102 | $decodedPoint = $p; |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | // find all the pages in the index that overlap with the adjacent hashes |
| 119 | 119 | $docIds = array(); |
| 120 | - foreach($adjacent as $adjHash) { |
|
| 121 | - if(is_array($this->spatial_idx)) { |
|
| 122 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
| 123 | - if(strpos($_geohash, $adjHash) !== false) { |
|
| 120 | + foreach ($adjacent as $adjHash) { |
|
| 121 | + if (is_array($this->spatial_idx)) { |
|
| 122 | + foreach ($this->spatial_idx as $_geohash => $_docIds) { |
|
| 123 | + if (strpos($_geohash, $adjHash) !== false) { |
|
| 124 | 124 | // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
| 125 | 125 | // if $adjHash similar to geohash |
| 126 | 126 | $docIds = array_merge($docIds, $_docIds); |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | $media = array(); |
| 137 | 137 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
| 138 | 138 | |
| 139 | - foreach($docIds as $id) { |
|
| 140 | - if(strpos($id, 'media__', 0) === 0) { |
|
| 139 | + foreach ($docIds as $id) { |
|
| 140 | + if (strpos($id, 'media__', 0) === 0) { |
|
| 141 | 141 | $id = substr($id, strlen('media__')); |
| 142 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 142 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 143 | 143 | $point = $indexer->getCoordsFromExif($id); |
| 144 | 144 | $line = new geoPHP\Geometry\LineString( |
| 145 | 145 | [ |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | ); |
| 150 | 150 | $media [] = array( |
| 151 | 151 | 'id' => $id, |
| 152 | - 'distance' => (int) ($line->greatCircleLength()), |
|
| 152 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
| 153 | 153 | 'lat' => $point->y(), |
| 154 | 154 | 'lon' => $point->x() |
| 155 | 155 | // optionally add other meta such as tag, description... |
| 156 | 156 | ); |
| 157 | 157 | } |
| 158 | 158 | } else { |
| 159 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 159 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
| 160 | 160 | $geotags = p_get_metadata($id, 'geo'); |
| 161 | 161 | $point = new geoPHP\Geometry\Point($geotags ['lon'], $geotags ['lat']); |
| 162 | 162 | $line = new geoPHP\Geometry\LineString( |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | ); |
| 168 | 168 | $pages [] = array( |
| 169 | 169 | 'id' => $id, |
| 170 | - 'distance' => (int) ($line->greatCircleLength()), |
|
| 170 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
| 171 | 171 | 'description' => p_get_metadata($id, 'description')['abstract'], |
| 172 | 172 | 'lat' => $geotags ['lat'], |
| 173 | 173 | 'lon' => $geotags ['lon'] |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | // sort all the pages/media using distance |
| 181 | 181 | usort( |
| 182 | - $pages, static function ($a, $b) { |
|
| 182 | + $pages, static function($a, $b) { |
|
| 183 | 183 | return strnatcmp($a ['distance'], $b ['distance']); |
| 184 | 184 | } |
| 185 | 185 | ); |
| 186 | 186 | usort( |
| 187 | - $media, static function ($a, $b) { |
|
| 187 | + $media, static function($a, $b) { |
|
| 188 | 188 | return strnatcmp($a ['distance'], $b ['distance']); |
| 189 | 189 | } |
| 190 | 190 | ); |
@@ -22,284 +22,284 @@ |
||
| 22 | 22 | * @author Mark Prins |
| 23 | 23 | */ |
| 24 | 24 | class helper_plugin_spatialhelper_index extends DokuWiki_Plugin { |
| 25 | - /** |
|
| 26 | - * directory for index files. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $idx_dir = ''; |
|
| 25 | + /** |
|
| 26 | + * directory for index files. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $idx_dir = ''; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * spatial index, well lookup list/array so we can do spatial queries. |
|
| 34 | - * entries should be: array("geohash" => {"id1","id3",}) |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $spatial_idx = array(); |
|
| 32 | + /** |
|
| 33 | + * spatial index, well lookup list/array so we can do spatial queries. |
|
| 34 | + * entries should be: array("geohash" => {"id1","id3",}) |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $spatial_idx = array(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * handle to the geoPHP plugin. |
|
| 42 | - */ |
|
| 43 | - protected $geophp; |
|
| 40 | + /** |
|
| 41 | + * handle to the geoPHP plugin. |
|
| 42 | + */ |
|
| 43 | + protected $geophp; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Constructor, initialises the spatial index. |
|
| 47 | - */ |
|
| 48 | - public function __construct() { |
|
| 49 | - if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 50 | - $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: geophp plugin is not available.'; |
|
| 51 | - msg($message, -1); |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * Constructor, initialises the spatial index. |
|
| 47 | + */ |
|
| 48 | + public function __construct() { |
|
| 49 | + if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 50 | + $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: geophp plugin is not available.'; |
|
| 51 | + msg($message, -1); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - global $conf; |
|
| 55 | - $this->idx_dir = $conf ['indexdir']; |
|
| 56 | - // test if there is a spatialindex, if not build one for the wiki |
|
| 57 | - if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
| 58 | - // creates and stores the index |
|
| 59 | - $this->generateSpatialIndex(); |
|
| 60 | - } else { |
|
| 61 | - $this->spatial_idx = unserialize(io_readFile($this->idx_dir . '/spatial.idx', false)); |
|
| 62 | - dbglog($this->spatial_idx, 'done loading spatial index'); |
|
| 63 | - } |
|
| 64 | - } |
|
| 54 | + global $conf; |
|
| 55 | + $this->idx_dir = $conf ['indexdir']; |
|
| 56 | + // test if there is a spatialindex, if not build one for the wiki |
|
| 57 | + if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
| 58 | + // creates and stores the index |
|
| 59 | + $this->generateSpatialIndex(); |
|
| 60 | + } else { |
|
| 61 | + $this->spatial_idx = unserialize(io_readFile($this->idx_dir . '/spatial.idx', false)); |
|
| 62 | + dbglog($this->spatial_idx, 'done loading spatial index'); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * (re-)Generates the spatial index by running through all the pages in the wiki. |
|
| 68 | - * |
|
| 69 | - * @todo add an option to erase the old index |
|
| 70 | - */ |
|
| 71 | - public function generateSpatialIndex(): bool { |
|
| 72 | - global $conf; |
|
| 73 | - require_once(DOKU_INC . 'inc/search.php'); |
|
| 74 | - $pages = array(); |
|
| 75 | - search($pages, $conf ['datadir'], 'search_allpages', array()); |
|
| 76 | - foreach($pages as $page) { |
|
| 77 | - $this->updateSpatialIndex($page ['id']); |
|
| 78 | - } |
|
| 79 | - // media |
|
| 80 | - $media = array(); |
|
| 81 | - search($media, $conf ['mediadir'], 'search_media', array()); |
|
| 82 | - foreach($media as $medium) { |
|
| 83 | - if($medium ['isimg']) { |
|
| 84 | - $this->indexImage($medium); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - return true; |
|
| 88 | - } |
|
| 66 | + /** |
|
| 67 | + * (re-)Generates the spatial index by running through all the pages in the wiki. |
|
| 68 | + * |
|
| 69 | + * @todo add an option to erase the old index |
|
| 70 | + */ |
|
| 71 | + public function generateSpatialIndex(): bool { |
|
| 72 | + global $conf; |
|
| 73 | + require_once(DOKU_INC . 'inc/search.php'); |
|
| 74 | + $pages = array(); |
|
| 75 | + search($pages, $conf ['datadir'], 'search_allpages', array()); |
|
| 76 | + foreach($pages as $page) { |
|
| 77 | + $this->updateSpatialIndex($page ['id']); |
|
| 78 | + } |
|
| 79 | + // media |
|
| 80 | + $media = array(); |
|
| 81 | + search($media, $conf ['mediadir'], 'search_media', array()); |
|
| 82 | + foreach($media as $medium) { |
|
| 83 | + if($medium ['isimg']) { |
|
| 84 | + $this->indexImage($medium); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + return true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Update the spatial index for the page. |
|
| 92 | - * |
|
| 93 | - * @param string $id |
|
| 94 | - * the document ID |
|
| 95 | - * @throws Exception |
|
| 96 | - */ |
|
| 97 | - public function updateSpatialIndex(string $id): bool { |
|
| 98 | - $geotags = p_get_metadata($id, 'geo'); |
|
| 99 | - if(empty ($geotags)) { |
|
| 100 | - return false; |
|
| 101 | - } |
|
| 102 | - if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - dbglog($geotags, "Geo metadata found for page $id"); |
|
| 106 | - $geometry = new geoPHP\Geometry\Point($geotags ['lon'], $geotags ['lat']); |
|
| 107 | - $geohash = $geometry->out('geohash'); |
|
| 108 | - dbglog('Update index for geohash: ' . $geohash); |
|
| 109 | - return $this->addToIndex($geohash, $id); |
|
| 110 | - } |
|
| 90 | + /** |
|
| 91 | + * Update the spatial index for the page. |
|
| 92 | + * |
|
| 93 | + * @param string $id |
|
| 94 | + * the document ID |
|
| 95 | + * @throws Exception |
|
| 96 | + */ |
|
| 97 | + public function updateSpatialIndex(string $id): bool { |
|
| 98 | + $geotags = p_get_metadata($id, 'geo'); |
|
| 99 | + if(empty ($geotags)) { |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | + if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + dbglog($geotags, "Geo metadata found for page $id"); |
|
| 106 | + $geometry = new geoPHP\Geometry\Point($geotags ['lon'], $geotags ['lat']); |
|
| 107 | + $geohash = $geometry->out('geohash'); |
|
| 108 | + dbglog('Update index for geohash: ' . $geohash); |
|
| 109 | + return $this->addToIndex($geohash, $id); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Store the hash/id entry in the index. |
|
| 114 | - * |
|
| 115 | - * @param string $geohash |
|
| 116 | - * @param string $id |
|
| 117 | - * page or media id |
|
| 118 | - * @return bool true when succesful |
|
| 119 | - */ |
|
| 120 | - private function addToIndex(string $geohash, string $id): bool { |
|
| 121 | - $pageIds = array(); |
|
| 122 | - // check index for key/geohash |
|
| 123 | - if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
| 124 | - dbglog("Geohash $geohash not in index, just add $id."); |
|
| 125 | - $pageIds [] = $id; |
|
| 126 | - } else { |
|
| 127 | - dbglog('Geohash for document is in index, find it.'); |
|
| 128 | - // check the index for document |
|
| 129 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 130 | - if(empty ($knownHashes)) { |
|
| 131 | - dbglog("No index record found for document $id, just add"); |
|
| 132 | - $pageIds = $this->spatial_idx [$geohash]; |
|
| 133 | - $pageIds [] = $id; |
|
| 134 | - } |
|
| 135 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
| 136 | - $knownHash = $knownHashes [0]; |
|
| 112 | + /** |
|
| 113 | + * Store the hash/id entry in the index. |
|
| 114 | + * |
|
| 115 | + * @param string $geohash |
|
| 116 | + * @param string $id |
|
| 117 | + * page or media id |
|
| 118 | + * @return bool true when succesful |
|
| 119 | + */ |
|
| 120 | + private function addToIndex(string $geohash, string $id): bool { |
|
| 121 | + $pageIds = array(); |
|
| 122 | + // check index for key/geohash |
|
| 123 | + if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
| 124 | + dbglog("Geohash $geohash not in index, just add $id."); |
|
| 125 | + $pageIds [] = $id; |
|
| 126 | + } else { |
|
| 127 | + dbglog('Geohash for document is in index, find it.'); |
|
| 128 | + // check the index for document |
|
| 129 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 130 | + if(empty ($knownHashes)) { |
|
| 131 | + dbglog("No index record found for document $id, just add"); |
|
| 132 | + $pageIds = $this->spatial_idx [$geohash]; |
|
| 133 | + $pageIds [] = $id; |
|
| 134 | + } |
|
| 135 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
| 136 | + $knownHash = $knownHashes [0]; |
|
| 137 | 137 | |
| 138 | - if($knownHash === $geohash) { |
|
| 139 | - dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 138 | + if($knownHash === $geohash) { |
|
| 139 | + dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if(!empty ($knownHash)) { |
|
| 144 | - dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
|
| 145 | - $knownIds = $this->spatial_idx [$knownHash]; |
|
| 146 | - dbglog($knownIds, "Known id's for this hash:"); |
|
| 147 | - // remove it from the old geohash element |
|
| 148 | - $i = array_search($id, $knownIds); |
|
| 149 | - dbglog('Unsetting:' . $knownIds [$i]); |
|
| 150 | - unset ($knownIds [$i]); |
|
| 151 | - $this->spatial_idx [$knownHash] = $knownIds; |
|
| 152 | - // set on new geohash element |
|
| 153 | - $pageIds = $this->spatial_idx [$geohash]; |
|
| 154 | - $pageIds [] = $id; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - // store and save |
|
| 158 | - $this->spatial_idx [$geohash] = $pageIds; |
|
| 159 | - return $this->saveIndex(); |
|
| 160 | - } |
|
| 143 | + if(!empty ($knownHash)) { |
|
| 144 | + dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
|
| 145 | + $knownIds = $this->spatial_idx [$knownHash]; |
|
| 146 | + dbglog($knownIds, "Known id's for this hash:"); |
|
| 147 | + // remove it from the old geohash element |
|
| 148 | + $i = array_search($id, $knownIds); |
|
| 149 | + dbglog('Unsetting:' . $knownIds [$i]); |
|
| 150 | + unset ($knownIds [$i]); |
|
| 151 | + $this->spatial_idx [$knownHash] = $knownIds; |
|
| 152 | + // set on new geohash element |
|
| 153 | + $pageIds = $this->spatial_idx [$geohash]; |
|
| 154 | + $pageIds [] = $id; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + // store and save |
|
| 158 | + $this->spatial_idx [$geohash] = $pageIds; |
|
| 159 | + return $this->saveIndex(); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Looks up the geohash(es) for the document in the index. |
|
| 164 | - * |
|
| 165 | - * @param String $id |
|
| 166 | - * document ID |
|
| 167 | - * @param array $index |
|
| 168 | - * spatial index |
|
| 169 | - */ |
|
| 170 | - public function findHashesForId(string $id, array $index): array { |
|
| 171 | - $hashes = array(); |
|
| 172 | - foreach($index as $hash => $docIds) { |
|
| 173 | - if(in_array($id, $docIds, false)) { |
|
| 174 | - $hashes [] = $hash; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - dbglog($hashes, "Found the following hashes for $id (should only be 1)"); |
|
| 178 | - return $hashes; |
|
| 179 | - } |
|
| 162 | + /** |
|
| 163 | + * Looks up the geohash(es) for the document in the index. |
|
| 164 | + * |
|
| 165 | + * @param String $id |
|
| 166 | + * document ID |
|
| 167 | + * @param array $index |
|
| 168 | + * spatial index |
|
| 169 | + */ |
|
| 170 | + public function findHashesForId(string $id, array $index): array { |
|
| 171 | + $hashes = array(); |
|
| 172 | + foreach($index as $hash => $docIds) { |
|
| 173 | + if(in_array($id, $docIds, false)) { |
|
| 174 | + $hashes [] = $hash; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + dbglog($hashes, "Found the following hashes for $id (should only be 1)"); |
|
| 178 | + return $hashes; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Save spatial index. |
|
| 183 | - */ |
|
| 184 | - private function saveIndex(): bool { |
|
| 185 | - return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx)); |
|
| 186 | - } |
|
| 181 | + /** |
|
| 182 | + * Save spatial index. |
|
| 183 | + */ |
|
| 184 | + private function saveIndex(): bool { |
|
| 185 | + return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx)); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Add an index entry for this file having EXIF / IPTC data. |
|
| 190 | - * |
|
| 191 | - * @param $img |
|
| 192 | - * a Dokuwiki image |
|
| 193 | - * @return bool true when image was succesfully added to the index. |
|
| 194 | - * @throws Exception |
|
| 195 | - * @see http://www.php.net/manual/en/function.iptcparse.php |
|
| 196 | - * @see http://php.net/manual/en/function.exif-read-data.php |
|
| 197 | - * |
|
| 198 | - */ |
|
| 199 | - public function indexImage($img): bool { |
|
| 200 | - // test for supported files (jpeg only) |
|
| 201 | - if( |
|
| 202 | - (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
|
| 203 | - (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 188 | + /** |
|
| 189 | + * Add an index entry for this file having EXIF / IPTC data. |
|
| 190 | + * |
|
| 191 | + * @param $img |
|
| 192 | + * a Dokuwiki image |
|
| 193 | + * @return bool true when image was succesfully added to the index. |
|
| 194 | + * @throws Exception |
|
| 195 | + * @see http://www.php.net/manual/en/function.iptcparse.php |
|
| 196 | + * @see http://php.net/manual/en/function.exif-read-data.php |
|
| 197 | + * |
|
| 198 | + */ |
|
| 199 | + public function indexImage($img): bool { |
|
| 200 | + // test for supported files (jpeg only) |
|
| 201 | + if( |
|
| 202 | + (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
|
| 203 | + (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $geometry = $this->getCoordsFromExif($img ['id']); |
|
| 208 | - if(!$geometry) { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - $geohash = $geometry->out('geohash'); |
|
| 212 | - // TODO truncate the geohash to something reasonable, otherwise they are |
|
| 213 | - // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too |
|
| 214 | - // precise, limit at ~9 as most GPS are not submeter accurate |
|
| 215 | - return $this->addToIndex($geohash, 'media__' . $img ['id']); |
|
| 216 | - } |
|
| 207 | + $geometry = $this->getCoordsFromExif($img ['id']); |
|
| 208 | + if(!$geometry) { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + $geohash = $geometry->out('geohash'); |
|
| 212 | + // TODO truncate the geohash to something reasonable, otherwise they are |
|
| 213 | + // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too |
|
| 214 | + // precise, limit at ~9 as most GPS are not submeter accurate |
|
| 215 | + return $this->addToIndex($geohash, 'media__' . $img ['id']); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * retrieve GPS decimal coordinates from exif. |
|
| 220 | - * |
|
| 221 | - * @param string $id |
|
| 222 | - * @return geoPHP\Geometry\Point|false |
|
| 223 | - * @throws Exception |
|
| 224 | - */ |
|
| 225 | - public function getCoordsFromExif(string $id) { |
|
| 226 | - $exif = exif_read_data(mediaFN($id), 0, true); |
|
| 227 | - if(empty ($exif ['GPS'])) { |
|
| 228 | - return false; |
|
| 229 | - } |
|
| 218 | + /** |
|
| 219 | + * retrieve GPS decimal coordinates from exif. |
|
| 220 | + * |
|
| 221 | + * @param string $id |
|
| 222 | + * @return geoPHP\Geometry\Point|false |
|
| 223 | + * @throws Exception |
|
| 224 | + */ |
|
| 225 | + public function getCoordsFromExif(string $id) { |
|
| 226 | + $exif = exif_read_data(mediaFN($id), 0, true); |
|
| 227 | + if(empty ($exif ['GPS'])) { |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $lat = $this->convertDMStoD( |
|
| 232 | - array( |
|
| 233 | - $exif ['GPS'] ['GPSLatitude'] [0], |
|
| 234 | - $exif ['GPS'] ['GPSLatitude'] [1], |
|
| 235 | - $exif ['GPS'] ['GPSLatitude'] [2], |
|
| 236 | - $exif ['GPS'] ['GPSLatitudeRef'] |
|
| 237 | - ) |
|
| 238 | - ); |
|
| 231 | + $lat = $this->convertDMStoD( |
|
| 232 | + array( |
|
| 233 | + $exif ['GPS'] ['GPSLatitude'] [0], |
|
| 234 | + $exif ['GPS'] ['GPSLatitude'] [1], |
|
| 235 | + $exif ['GPS'] ['GPSLatitude'] [2], |
|
| 236 | + $exif ['GPS'] ['GPSLatitudeRef'] |
|
| 237 | + ) |
|
| 238 | + ); |
|
| 239 | 239 | |
| 240 | - $lon = $this->convertDMStoD( |
|
| 241 | - array( |
|
| 242 | - $exif ['GPS'] ['GPSLongitude'] [0], |
|
| 243 | - $exif ['GPS'] ['GPSLongitude'] [1], |
|
| 244 | - $exif ['GPS'] ['GPSLongitude'] [2], |
|
| 245 | - $exif ['GPS'] ['GPSLongitudeRef'] |
|
| 246 | - ) |
|
| 247 | - ); |
|
| 240 | + $lon = $this->convertDMStoD( |
|
| 241 | + array( |
|
| 242 | + $exif ['GPS'] ['GPSLongitude'] [0], |
|
| 243 | + $exif ['GPS'] ['GPSLongitude'] [1], |
|
| 244 | + $exif ['GPS'] ['GPSLongitude'] [2], |
|
| 245 | + $exif ['GPS'] ['GPSLongitudeRef'] |
|
| 246 | + ) |
|
| 247 | + ); |
|
| 248 | 248 | |
| 249 | - return new geoPHP\Geometry\Point($lon, $lat); |
|
| 250 | - } |
|
| 249 | + return new geoPHP\Geometry\Point($lon, $lat); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * convert DegreesMinutesSeconds to Decimal degrees. |
|
| 254 | - * |
|
| 255 | - * @param array $param array of rational DMS |
|
| 256 | - * @return float |
|
| 257 | - */ |
|
| 258 | - public function convertDMStoD(array $param): float { |
|
| 259 | - if(!is_array($param)) { |
|
| 260 | - $param = array($param); |
|
| 261 | - } |
|
| 262 | - $deg = $this->convertRationaltoFloat($param [0]); |
|
| 263 | - $min = $this->convertRationaltoFloat($param [1]) / 60; |
|
| 264 | - $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60; |
|
| 265 | - // Hemisphere (N, S, W or E) |
|
| 266 | - $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1; |
|
| 267 | - return $hem * ($deg + $min + $sec); |
|
| 268 | - } |
|
| 252 | + /** |
|
| 253 | + * convert DegreesMinutesSeconds to Decimal degrees. |
|
| 254 | + * |
|
| 255 | + * @param array $param array of rational DMS |
|
| 256 | + * @return float |
|
| 257 | + */ |
|
| 258 | + public function convertDMStoD(array $param): float { |
|
| 259 | + if(!is_array($param)) { |
|
| 260 | + $param = array($param); |
|
| 261 | + } |
|
| 262 | + $deg = $this->convertRationaltoFloat($param [0]); |
|
| 263 | + $min = $this->convertRationaltoFloat($param [1]) / 60; |
|
| 264 | + $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60; |
|
| 265 | + // Hemisphere (N, S, W or E) |
|
| 266 | + $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1; |
|
| 267 | + return $hem * ($deg + $min + $sec); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - public function convertRationaltoFloat($param): float { |
|
| 271 | - // rational64u |
|
| 272 | - $nums = explode('/', $param); |
|
| 273 | - if((int) $nums[1] > 0) { |
|
| 274 | - return (float) $nums[0] / (int) $nums[1]; |
|
| 275 | - } else { |
|
| 276 | - return (float) $nums[0]; |
|
| 277 | - } |
|
| 278 | - } |
|
| 270 | + public function convertRationaltoFloat($param): float { |
|
| 271 | + // rational64u |
|
| 272 | + $nums = explode('/', $param); |
|
| 273 | + if((int) $nums[1] > 0) { |
|
| 274 | + return (float) $nums[0] / (int) $nums[1]; |
|
| 275 | + } else { |
|
| 276 | + return (float) $nums[0]; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Deletes the page from the index. |
|
| 282 | - * |
|
| 283 | - * @param string $id document ID |
|
| 284 | - */ |
|
| 285 | - public function deleteFromIndex(string $id): void { |
|
| 286 | - // check the index for document |
|
| 287 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 288 | - if(empty ($knownHashes)) { |
|
| 289 | - return; |
|
| 290 | - } |
|
| 280 | + /** |
|
| 281 | + * Deletes the page from the index. |
|
| 282 | + * |
|
| 283 | + * @param string $id document ID |
|
| 284 | + */ |
|
| 285 | + public function deleteFromIndex(string $id): void { |
|
| 286 | + // check the index for document |
|
| 287 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 288 | + if(empty ($knownHashes)) { |
|
| 289 | + return; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
| 293 | - $knownHash = $knownHashes [0]; |
|
| 294 | - $knownIds = $this->spatial_idx [$knownHash]; |
|
| 295 | - $i = array_search($id, $knownIds); |
|
| 296 | - dbglog("removing: $knownIds[$i] from the index."); |
|
| 297 | - unset ($knownIds [$i]); |
|
| 298 | - $this->spatial_idx [$knownHash] = $knownIds; |
|
| 299 | - if(empty ($this->spatial_idx [$knownHash])) { |
|
| 300 | - // dbglog ( "removing key: $knownHash from the index." ); |
|
| 301 | - unset ($this->spatial_idx [$knownHash]); |
|
| 302 | - } |
|
| 303 | - $this->saveIndex(); |
|
| 304 | - } |
|
| 292 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
| 293 | + $knownHash = $knownHashes [0]; |
|
| 294 | + $knownIds = $this->spatial_idx [$knownHash]; |
|
| 295 | + $i = array_search($id, $knownIds); |
|
| 296 | + dbglog("removing: $knownIds[$i] from the index."); |
|
| 297 | + unset ($knownIds [$i]); |
|
| 298 | + $this->spatial_idx [$knownHash] = $knownIds; |
|
| 299 | + if(empty ($this->spatial_idx [$knownHash])) { |
|
| 300 | + // dbglog ( "removing key: $knownHash from the index." ); |
|
| 301 | + unset ($this->spatial_idx [$knownHash]); |
|
| 302 | + } |
|
| 303 | + $this->saveIndex(); |
|
| 304 | + } |
|
| 305 | 305 | } |