Download web/src/controllers/SearchController.php from datamatters24/research-document-archive: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/datamatters24/research-document-archive/resolve/main/web/src/controllers/SearchController.php
- Command line
-
hf download hf://datamatters24/research-document-archive/web/src/controllers/SearchController.php
-
curl -L -o SearchController.php https://huggingface.co/datamatters24/research-document-archive/resolve/main/web/src/controllers/SearchController.php
2.48 kB
| declare(strict_types=1); | |
| class SearchController | |
| { | |
| /** | |
| * Full-text search with optional collection filter and pagination. | |
| */ | |
| public function index(): void | |
| { | |
| $config = require __DIR__ . '/../config.php'; | |
| $query = Security::sanitizeSearch($_GET['q'] ?? ''); | |
| $collection = isset($_GET['collection']) && $_GET['collection'] !== '' | |
| ? Security::sanitize($_GET['collection']) | |
| : null; | |
| $topicFilter = isset($_GET['topic']) && $_GET['topic'] !== '' | |
| ? Security::sanitize($_GET['topic']) | |
| : null; | |
| $stampFilter = isset($_GET['stamp']) && $_GET['stamp'] !== '' | |
| ? Security::sanitize($_GET['stamp']) | |
| : null; | |
| $perPage = $config['app']['per_page']; | |
| $limit = min($perPage, $config['app']['search_limit']); | |
| $page = max(1, (int) ($_GET['page'] ?? 1)); | |
| $offset = ($page - 1) * $limit; | |
| $results = []; | |
| $total = 0; | |
| $totalPages = 0; | |
| if ($query !== '') { | |
| $searchModel = new Search(); | |
| $results = $searchModel->fullText($query, $collection, $limit, $offset, $topicFilter, $stampFilter); | |
| $total = $searchModel->countResults($query, $collection, $topicFilter, $stampFilter); | |
| $totalPages = (int) ceil($total / $limit); | |
| } | |
| // Gather collection list for the filter dropdown | |
| $docModel = new Document(); | |
| $collections = $docModel->getCollections(); | |
| // Available topics and stamps for filter dropdowns | |
| $db = Database::getInstance(); | |
| $availableTopics = []; | |
| $availableStamps = []; | |
| try { | |
| $availableTopics = [ | |
| 'intelligence operations', 'national security', 'military operations', | |
| 'surveillance', 'assassination', 'congressional legislation', | |
| 'government oversight', 'civil rights', 'foreign policy', | |
| 'law enforcement', 'financial regulation', 'public health', | |
| 'human experimentation', 'scientific research', 'judicial proceedings', | |
| ]; | |
| $availableStamps = [ | |
| 'TOP SECRET', 'SECRET', 'CONFIDENTIAL', 'CLASSIFIED', 'UNCLASSIFIED', | |
| 'NOFORN', 'EYES ONLY', 'REDACTED', 'DECLASSIFIED', 'SEALED', | |
| ]; | |
| } catch (\PDOException $e) {} | |
| require __DIR__ . '/../views/search-results.php'; | |
| } | |
| } | |