datamatters24 commited on
Commit
b16040e
·
verified ·
1 Parent(s): 5be2108

Upload web/src/controllers/SearchController.php with huggingface_hub

Browse files
web/src/controllers/SearchController.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ class SearchController
6
+ {
7
+ /**
8
+ * Full-text search with optional collection filter and pagination.
9
+ */
10
+ public function index(): void
11
+ {
12
+ $config = require __DIR__ . '/../config.php';
13
+
14
+ $query = Security::sanitizeSearch($_GET['q'] ?? '');
15
+ $collection = isset($_GET['collection']) && $_GET['collection'] !== ''
16
+ ? Security::sanitize($_GET['collection'])
17
+ : null;
18
+ $topicFilter = isset($_GET['topic']) && $_GET['topic'] !== ''
19
+ ? Security::sanitize($_GET['topic'])
20
+ : null;
21
+ $stampFilter = isset($_GET['stamp']) && $_GET['stamp'] !== ''
22
+ ? Security::sanitize($_GET['stamp'])
23
+ : null;
24
+
25
+ $perPage = $config['app']['per_page'];
26
+ $limit = min($perPage, $config['app']['search_limit']);
27
+ $page = max(1, (int) ($_GET['page'] ?? 1));
28
+ $offset = ($page - 1) * $limit;
29
+
30
+ $results = [];
31
+ $total = 0;
32
+ $totalPages = 0;
33
+
34
+ if ($query !== '') {
35
+ $searchModel = new Search();
36
+ $results = $searchModel->fullText($query, $collection, $limit, $offset, $topicFilter, $stampFilter);
37
+ $total = $searchModel->countResults($query, $collection, $topicFilter, $stampFilter);
38
+ $totalPages = (int) ceil($total / $limit);
39
+ }
40
+
41
+ // Gather collection list for the filter dropdown
42
+ $docModel = new Document();
43
+ $collections = $docModel->getCollections();
44
+
45
+ // Available topics and stamps for filter dropdowns
46
+ $db = Database::getInstance();
47
+ $availableTopics = [];
48
+ $availableStamps = [];
49
+ try {
50
+ $availableTopics = [
51
+ 'intelligence operations', 'national security', 'military operations',
52
+ 'surveillance', 'assassination', 'congressional legislation',
53
+ 'government oversight', 'civil rights', 'foreign policy',
54
+ 'law enforcement', 'financial regulation', 'public health',
55
+ 'human experimentation', 'scientific research', 'judicial proceedings',
56
+ ];
57
+ $availableStamps = [
58
+ 'TOP SECRET', 'SECRET', 'CONFIDENTIAL', 'CLASSIFIED', 'UNCLASSIFIED',
59
+ 'NOFORN', 'EYES ONLY', 'REDACTED', 'DECLASSIFIED', 'SEALED',
60
+ ];
61
+ } catch (\PDOException $e) {}
62
+
63
+ require __DIR__ . '/../views/search-results.php';
64
+ }
65
+ }