Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions src/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
->bind('homepage')
;

$app->get('/libraries', function () {
return "Library index page";
$app->get('/library/{id}', function ($id) use ($app) {
return $app['twig']->render('library.html.twig', array('id' => $id));
});

$app->get('/library_api/{id}', function ($id) use ($app) {

$client = $app['elasticsearch'];
$params = [
'index' => 'publiclib',
'index' => 'publiclibdata',
'type' => 'logs',
'size' => 500,
'body' => [
'query' => [
'match' => [
Expand All @@ -41,6 +42,27 @@
})
->value("id", "*"); // set a default value

$app->get('/library_year/{id}', function ($id) use ($app) {

$client = $app['elasticsearch'];
$params = [
'index' => 'publiclibdata',
'type' => 'logs',
'size' => 500,
'body' => [
'query' => [
'match' => [
'Year' => trim($id)
]
]
]
];

$response = $client->search($params);
return new JsonResponse($response);
})
->value("id", "2016"); // set a default value

$app->error(function (\Exception $e, Request $request, $code) use ($app) {
if ($app['debug']) {
return;
Expand All @@ -56,3 +78,46 @@

return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
});

$app->get('/library_api_autocomplete/{id}', function ($id) use ($app) {
// example query http://localhost:8282/library_api_autocomplete/*
// This one uses the new, fixed index
// Facets come back in the Buckets object
if (empty($id)) {
$id = "*";
}
$client = $app['elasticsearch'];
$params = [
'index' => 'publiclibdata',
'type' => 'logs',
'from' => 0,
'size' => 100,
"_source" => [
"Location"
],
'body' => [
'query' => [
"query_string" => [
"default_field" => "Location",
"query" => "{$id}"
]
],
"aggregations" => [
"libraries" => [
"terms" => [
"field" => "Location.keyword",
"size" => 500
]
],
"Years" => [
"terms" => [
"field" => "Year.keyword"
]
],
]
]
];
$response = $client->search($params);
return new JsonResponse($response);
})
->value("id", "*"); // set a default value