diff --git a/Admin/Install/Search.php b/Admin/Install/Search.php new file mode 100644 index 0000000..7d09343 --- /dev/null +++ b/Admin/Install/Search.php @@ -0,0 +1,43 @@ + __DIR__ . '/SearchCommands.php']); + } +} diff --git a/Admin/Install/SearchCommands.php b/Admin/Install/SearchCommands.php new file mode 100644 index 0000000..2b574be --- /dev/null +++ b/Admin/Install/SearchCommands.php @@ -0,0 +1,32 @@ + [ + [ + 'dest' => '\Modules\Media\Controller\SearchController:searchGeneral', + 'verb' => RouteVerb::ANY, + 'permission' => [ + 'module' => SearchController::NAME, + 'type' => PermissionType::READ, + 'state' => PermissionCategory::MEDIA, + ], + ], + ], +]; diff --git a/Controller/SearchController.php b/Controller/SearchController.php new file mode 100644 index 0000000..6473440 --- /dev/null +++ b/Controller/SearchController.php @@ -0,0 +1,76 @@ +with('tags') + ->with('tags/title') + ->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') + ->where('tags/title/language', $response->header->l11n->language) + ->sort('createdAt', OrderType::DESC) + ->limit(8) + ->execute(); + + $results = []; + foreach ($media as $file) { + $results[] = [ + 'title' => $file->name . ' (' . $file->extension . ')', + 'summary' => '', + 'link' => '{/base}/media/view?id=' . $file->id, + 'account' => '', + 'createdAt' => $file->createdAt, + 'image' => '', + 'tags' => $file->tags, + 'type' => 'list_links', + 'module' => 'Media', + ]; + } + + $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->add($request->uri->__toString(), $results); + } +} diff --git a/Models/Elastic/Media.json b/Models/Elastic/Media.json new file mode 100644 index 0000000..02b5089 --- /dev/null +++ b/Models/Elastic/Media.json @@ -0,0 +1,9 @@ +{ + "id": "{id}", + "title": "{title}", + "content": "{content}", + "extension": "{extension}", + "path": "{path}", + "types": ["{types}"], + "tags": ["{tags}"] +} \ No newline at end of file diff --git a/info.json b/info.json index 66dad5a..89a1a37 100755 --- a/info.json +++ b/info.json @@ -24,7 +24,8 @@ }, "providing": { "Navigation": "*", - "Media": "*" + "Media": "*", + "Search": "*" }, "load": [ {