Skip to content
Snippets Groups Projects
Commit b5d962df authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Bei einer Suche im Iframe wird nun entweder ein leeres Dokument zurückgegeben,...

Bei einer Suche im Iframe wird nun entweder ein leeres Dokument zurückgegeben, oder eine entsprechende Karte
Des weiteren wurde ein Cache für die Suche eingebaut. Dieser speichert alle Suchergebnisse für eine Woche
parent 64c0a6a7
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ update(maps.metager.de): ...@@ -16,7 +16,7 @@ update(maps.metager.de):
- cp -r * ~/.MetaGerMaps - cp -r * ~/.MetaGerMaps
- cd ~/.MetaGerMaps - cd ~/.MetaGerMaps
- composer install - composer install
- scp -P 63824 metager@metager3.de:~/.env . - cp ~/.env .
- chmod -R 777 storage - chmod -R 777 storage
- chmod -R 777 bootstrap/cache - chmod -R 777 bootstrap/cache
- if [ -f ~/MetaGerMaps/artisan ]; then php ~/MetaGerMaps/artisan down;fi - if [ -f ~/MetaGerMaps/artisan ]; then php ~/MetaGerMaps/artisan down;fi
......
...@@ -2,12 +2,21 @@ ...@@ -2,12 +2,21 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Cache;
use Predis\Connection\ConnectionException;
use Response; use Response;
use \Illuminate\Http\Request; use \Illuminate\Http\Request;
class SearchController extends Controller class SearchController extends Controller
{ {
//
public function search($search)
{
$link = "https://maps.metager.de/nominatim/search.php?q=" . urlencode($search) . "&limit=10&polygon_geojson=1&format=json&extratags=1&addressdetails=1";
$searchResults = $this->makeSearch($link);
return $searchResults;
}
public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $latMax, $lonMax, $adjustView = true, $limit = 50) public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $latMax, $lonMax, $adjustView = true, $limit = 50)
{ {
$exactSearch = filter_var($request->input('exactSearch', 'false'), FILTER_VALIDATE_BOOLEAN); $exactSearch = filter_var($request->input('exactSearch', 'false'), FILTER_VALIDATE_BOOLEAN);
...@@ -20,13 +29,37 @@ public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $ ...@@ -20,13 +29,37 @@ public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $
$boundingSuccess = true; $boundingSuccess = true;
# Get The Search Results # Get The Search Results
$link = "https://maps.metager.de/nominatim/search.php?q=" . urlencode($search) . "&limit=$limit&bounded=1&polygon_geojson=1&viewbox=$latMin,$lonMin,$latMax,$lonMax&format=json&extratags=1&addressdetails=1"; $link = "https://maps.metager.de/nominatim/search.php?q=" . urlencode($search) . "&limit=$limit&bounded=1&polygon_geojson=1&viewbox=$latMin,$lonMin,$latMax,$lonMax&format=json&extratags=1&addressdetails=1";
$results = json_decode(file_get_contents($link), true); $results = $this->makeSearch($link, $exactSearch);
if (!$results && $latMin && $lonMin && $latMax && $lonMax) { if (!$results && $latMin && $lonMin && $latMax && $lonMax) {
$boundingSuccess = false; $boundingSuccess = false;
$link = "https://maps.metager.de/nominatim/search.php?q=" . urlencode($search) . "&limit=$limit&polygon_geojson=1&format=json&extratags=1&addressdetails=1"; $link = "https://maps.metager.de/nominatim/search.php?q=" . urlencode($search) . "&limit=$limit&polygon_geojson=1&format=json&extratags=1&addressdetails=1";
$results = json_decode(file_get_contents($link), true); $results = $this->makeSearch($link);
}
# Wir erstellen die Ergebnisseite (JavaScipt)
$response = Response::make(view('searchResults')->with("results", json_encode($results))->with('adjustView', $adjustView)->with('boundingSuccess', $boundingSuccess)->with('bounds', [$latMin, $lonMin, $latMax, $lonMax])->with('search', $search)->with('adjustLink', $adjustLink), 200);
$response->header('Content-Type', 'application/javascript');
return $response;
}
private function makeSearch($link, $exactSearch = false)
{
$results = [];
if ($this->canCache()) {
$hash = md5($link);
if (Cache::has($hash)) {
$results = unserialize(base64_decode(Cache::get($hash)));
} else {
$results = json_decode(file_get_contents($link), true);
Cache::put($hash, base64_encode(serialize($results)), 10080);
}
} else {
# If the Cache is not there we can just execute a search
$results = json_decode(file_get_contents($link), true);
} }
$searchResults = []; $searchResults = [];
if ($results) { if ($results) {
foreach ($results as $result) { foreach ($results as $result) {
...@@ -62,10 +95,18 @@ public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $ ...@@ -62,10 +95,18 @@ public function boundingBoxSearch(Request $request, $search, $latMin, $lonMin, $
$searchResults[] = $tmp; $searchResults[] = $tmp;
} }
} }
# Wir erstellen die Ergebnisseite (JavaScipt) return $searchResults;
$response = Response::make(view('searchResults')->with("results", json_encode($searchResults))->with('adjustView', $adjustView)->with('boundingSuccess', $boundingSuccess)->with('bounds', [$latMin, $lonMin, $latMax, $lonMax])->with('search', $search)->with('adjustLink', $adjustLink), 200); }
$response->header('Content-Type', 'application/javascript');
return $response; private function canCache()
{
# Cachebarkeit testen
try {
Cache::has('test');
return true;
} catch (ConnectionException $e) {
return false;
}
} }
public function iframeSearch($search) public function iframeSearch($search)
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=5.6.4", "php": ">=5.6.4",
"laravel/framework": "5.3.*" "laravel/framework": "5.3.*",
"predis/predis": "^1.1"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "ed9df8b872992035f068a7fe461a635a", "hash": "ed505f794cc52c9b7a35ed0b2faccac0",
"content-hash": "76036da3b5b55b91dbe1e1affa01bf9e", "content-hash": "7e0e05e84f3eb333685719e2006b48a7",
"packages": [ "packages": [
{ {
"name": "classpreloader/classpreloader", "name": "classpreloader/classpreloader",
...@@ -785,6 +785,56 @@ ...@@ -785,6 +785,56 @@
], ],
"time": "2016-10-17 15:23:22" "time": "2016-10-17 15:23:22"
}, },
{
"name": "predis/predis",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/nrk/predis.git",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"suggest": {
"ext-curl": "Allows access to Webdis when paired with phpiredis",
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
},
"type": "library",
"autoload": {
"psr-4": {
"Predis\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla@gmail.com",
"homepage": "http://clorophilla.net"
}
],
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
"homepage": "http://github.com/nrk/predis",
"keywords": [
"nosql",
"predis",
"redis"
],
"time": "2016-06-16 16:22:20"
},
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.0.2", "version": "1.0.2",
......
...@@ -13,9 +13,9 @@ return [ ...@@ -13,9 +13,9 @@ return [
| |
| Supported: "apc", "array", "database", "file", "memcached", "redis" | Supported: "apc", "array", "database", "file", "memcached", "redis"
| |
*/ */
'default' => env('CACHE_DRIVER', 'file'), 'default' => env('CACHE_DRIVER', 'redis'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -26,50 +26,50 @@ return [ ...@@ -26,50 +26,50 @@ return [
| well as their drivers. You may even define multiple stores for the | well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches. | same cache driver to group types of items stored in your caches.
| |
*/ */
'stores' => [ 'stores' => [
'apc' => [ 'apc' => [
'driver' => 'apc', 'driver' => 'apc',
], ],
'array' => [ 'array' => [
'driver' => 'array', 'driver' => 'array',
], ],
'database' => [ 'database' => [
'driver' => 'database', 'driver' => 'database',
'table' => 'cache', 'table' => 'cache',
'connection' => null, 'connection' => null,
], ],
'file' => [ 'file' => [
'driver' => 'file', 'driver' => 'file',
'path' => storage_path('framework/cache'), 'path' => storage_path('framework/cache'),
], ],
'memcached' => [ 'memcached' => [
'driver' => 'memcached', 'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [ 'sasl' => [
env('MEMCACHED_USERNAME'), env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'), env('MEMCACHED_PASSWORD'),
], ],
'options' => [ 'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000, // Memcached::OPT_CONNECT_TIMEOUT => 2000,
], ],
'servers' => [ 'servers' => [
[ [
'host' => env('MEMCACHED_HOST', '127.0.0.1'), 'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211), 'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100, 'weight' => 100,
], ],
], ],
], ],
'redis' => [ 'redis' => [
'driver' => 'redis', 'driver' => 'redis',
'connection' => 'default', 'connection' => 'default',
], ],
...@@ -84,8 +84,8 @@ return [ ...@@ -84,8 +84,8 @@ return [
| be other applications utilizing the same cache. So, we'll specify a | be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions. | value to get prefixed to all our keys so we can avoid collisions.
| |
*/ */
'prefix' => 'laravel', 'prefix' => 'laravel',
]; ];
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
body { body {
max-height: 300px; max-height: 300px;
visibility: hidden;
} }
#map-container { #map-container {
......
...@@ -30,18 +30,15 @@ ...@@ -30,18 +30,15 @@
$(document).ready(function(){ $(document).ready(function(){
updateMapExtent(); updateMapExtent();
var q = '{{$search}}'; var q = '{{$search}}';
var url = '/' + q + '/' + encodeURI(extent[0]) + '/' + encodeURI(extent[1]) + '/' + encodeURI(extent[2]) + '/' + encodeURI(extent[3]) + '/' + true + '/10?exactSearch=true&adjustLink=false'; {!! $script !!}
$.getScript(url, function(){ if(typeof searchResults !== "undefined" && searchResults.length > 0){
if(typeof searchResults !== "undefined" && searchResults.length > 0){ $("body").css("visibility", "visible");
$("body").css("visibility", "visible"); }
} $("#results .result, #map").click(function(){
var link = "https://maps.metager.de/map" + '/' + q + '/' + encodeURI(extent[0]) + '/' + encodeURI(extent[1]) + '/' + encodeURI(extent[2]) + '/' + encodeURI(extent[3]); updateMapExtent();
$("#results .result, #map").click(function(){ window.open(link);
updateMapExtent();
window.open(link);
});
$(".result .btn").click(function(e){e.stopPropagation();});
}); });
$(".result .btn").click(function(e){e.stopPropagation();});
}); });
</script> </script>
</body> </body>
......
...@@ -21,7 +21,19 @@ Route::get('map/{search}/{latMin}/{lonMin}/{latMax}/{lonMax}', function ($search ...@@ -21,7 +21,19 @@ Route::get('map/{search}/{latMin}/{lonMin}/{latMax}/{lonMax}', function ($search
Route::get('{search}/{latMin}/{lonMin}/{latMax}/{lonMax}/{adjustView?}/{limit?}', 'SearchController@boundingBoxSearch'); Route::get('{search}/{latMin}/{lonMin}/{latMax}/{lonMax}/{adjustView?}/{limit?}', 'SearchController@boundingBoxSearch');
Route::get('metager/{search}', function ($search) { Route::get('{search}', 'SearchController@search');
# Wir erstellen die Ergebnisseite (JavaScipt)
return view('mapIframe')->with('search', $search); Route::group(['prefix' => 'metager'], function () {
Route::get('{search}', function ($search) {
# Let's get some Searchresults if existent
$searchResults = app('\App\Http\Controllers\SearchController')->search($search);
if (sizeof($searchResults) > 0) {
$javaScript = view('searchResults')->with("results", json_encode($searchResults))->with('adjustView', true)->with('boundingSuccess', true)->with('search', $search)->with('adjustLink', false);
# Wir erstellen die Ergebnisseite (JavaScipt)
return view('mapIframe')->with('search', $search)->with('script', $javaScript);
} else {
return view('empty');
}
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment