datamatters24 commited on
Commit
546ae02
·
verified ·
1 Parent(s): fe0fc54

Upload web/src/views/search-results.php with huggingface_hub

Browse files
Files changed (1) hide show
  1. web/src/views/search-results.php +249 -0
web/src/views/search-results.php ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Search Results Page
4
+ *
5
+ * Variables:
6
+ * $query - Current search query string
7
+ * $collection - Selected collection filter (or empty/null for all)
8
+ * $results - Array of search results with: document_id, document_name, file_path,
9
+ * source_section, page_number, snippet (may contain <mark> tags)
10
+ * $total - Total number of matching results
11
+ * $page - Current page number
12
+ * $perPage - Results per page
13
+ */
14
+
15
+ $page = $page ?? 1;
16
+ $perPage = $perPage ?? 25;
17
+ $totalPages = ($perPage > 0) ? (int)ceil(($total ?? 0) / $perPage) : 1;
18
+ $query = $query ?? '';
19
+ $collection = $collection ?? '';
20
+
21
+ $collectionNames = [
22
+ '' => 'All Collections',
23
+ 'jfk_assassination' => 'JFK Assassination Records',
24
+ 'cia_declassified' => 'CIA Declassified',
25
+ 'cia_stargate' => 'CIA Stargate Program',
26
+ 'cia_mkultra' => 'CIA MKUltra',
27
+ 'lincoln_archives' => 'Lincoln Archives',
28
+ 'house_resolutions' => 'House Resolutions',
29
+ 'nasa_apod' => 'NASA APOD',
30
+ 'nasa_epic' => 'NASA EPIC',
31
+ 'area51_cia' => 'Area 51 / CIA Declassified',
32
+ 'court_records' => 'Court Records',
33
+ 'foia' => 'FOIA Releases',
34
+ 'house_oversight' => 'House Oversight',
35
+ ];
36
+
37
+ $collectionBadgeColors = [
38
+ 'jfk_assassination' => 'bg-purple-100 text-purple-700',
39
+ 'cia_declassified' => 'bg-emerald-100 text-emerald-700',
40
+ 'cia_stargate' => 'bg-teal-100 text-teal-700',
41
+ 'cia_mkultra' => 'bg-rose-100 text-rose-700',
42
+ 'lincoln_archives' => 'bg-amber-100 text-amber-700',
43
+ 'house_resolutions' => 'bg-blue-100 text-blue-700',
44
+ 'nasa_apod' => 'bg-indigo-100 text-indigo-700',
45
+ 'nasa_epic' => 'bg-sky-100 text-sky-700',
46
+ 'area51_cia' => 'bg-emerald-100 text-emerald-700',
47
+ 'court_records' => 'bg-slate-100 text-slate-700',
48
+ 'foia' => 'bg-cyan-100 text-cyan-700',
49
+ 'house_oversight' => 'bg-orange-100 text-orange-700',
50
+ ];
51
+
52
+ $title = ($query ? htmlspecialchars($query) . ' - ' : '') . 'Search - Research Document Archive';
53
+ $content = '';
54
+ ob_start();
55
+ ?>
56
+
57
+ <!-- Search Form -->
58
+ <div class="mb-5">
59
+ <h1 class="text-xl font-bold text-gray-900 mb-4">Search Documents</h1>
60
+
61
+ <form action="/search" method="GET">
62
+ <div class="flex flex-col sm:flex-row gap-2">
63
+ <!-- Search Input -->
64
+ <div class="relative flex-1">
65
+ <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
66
+ <svg class="h-4 w-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
67
+ <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
68
+ </svg>
69
+ </div>
70
+ <input type="text" name="q" value="<?= htmlspecialchars($query) ?>"
71
+ placeholder="Search text content, entities, titles..."
72
+ class="w-full pl-9 pr-3 py-2 text-sm border border-gray-300 rounded-lg
73
+ focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-200
74
+ transition-all placeholder-gray-400">
75
+ </div>
76
+
77
+ <!-- Collection Filter -->
78
+ <div class="sm:w-52">
79
+ <select name="collection"
80
+ class="w-full py-2 px-3 text-sm border border-gray-300 rounded-lg
81
+ focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-200
82
+ transition-all bg-white text-gray-700">
83
+ <?php foreach ($collectionNames as $key => $label): ?>
84
+ <option value="<?= htmlspecialchars($key) ?>"
85
+ <?= $collection === $key ? 'selected' : '' ?>>
86
+ <?= htmlspecialchars($label) ?>
87
+ </option>
88
+ <?php endforeach; ?>
89
+ </select>
90
+ </div>
91
+
92
+ <!-- Submit -->
93
+ <button type="submit"
94
+ class="px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg
95
+ hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500
96
+ focus:ring-offset-1 transition-colors whitespace-nowrap">
97
+ Search
98
+ </button>
99
+ </div>
100
+
101
+ <!-- Advanced Filters -->
102
+ <details class="mt-2">
103
+ <summary class="text-xs text-gray-500 cursor-pointer hover:text-gray-700">Advanced Filters</summary>
104
+ <div class="flex flex-wrap gap-2 mt-2">
105
+ <!-- Topic Filter -->
106
+ <select name="topic" class="py-1.5 px-2 text-xs border border-gray-300 rounded-md bg-white text-gray-700">
107
+ <option value="">Any Topic</option>
108
+ <?php foreach ($availableTopics ?? [] as $t): ?>
109
+ <option value="<?= htmlspecialchars($t) ?>" <?= ($topicFilter ?? '') === $t ? 'selected' : '' ?>>
110
+ <?= htmlspecialchars(ucwords($t)) ?>
111
+ </option>
112
+ <?php endforeach; ?>
113
+ </select>
114
+
115
+ <!-- Stamp Filter -->
116
+ <select name="stamp" class="py-1.5 px-2 text-xs border border-gray-300 rounded-md bg-white text-gray-700">
117
+ <option value="">Any Classification</option>
118
+ <?php foreach ($availableStamps ?? [] as $s): ?>
119
+ <option value="<?= htmlspecialchars($s) ?>" <?= ($stampFilter ?? '') === $s ? 'selected' : '' ?>>
120
+ <?= htmlspecialchars($s) ?>
121
+ </option>
122
+ <?php endforeach; ?>
123
+ </select>
124
+
125
+ <?php if (!empty($topicFilter) || !empty($stampFilter)): ?>
126
+ <a href="/search?q=<?= urlencode($query) ?>&collection=<?= urlencode($collection) ?>"
127
+ class="inline-flex items-center px-2 py-1.5 text-xs text-red-600 hover:text-red-800">
128
+ Clear filters
129
+ </a>
130
+ <?php endif; ?>
131
+ </div>
132
+ </details>
133
+ </form>
134
+ </div>
135
+
136
+ <!-- Results -->
137
+ <?php if ($query): ?>
138
+
139
+ <!-- Result Count -->
140
+ <div class="flex items-center justify-between mb-4">
141
+ <p class="text-sm text-gray-600">
142
+ <?php if ($total > 0): ?>
143
+ Showing
144
+ <span class="font-semibold text-gray-900"><?= number_format(($page - 1) * $perPage + 1) ?></span>
145
+ to
146
+ <span class="font-semibold text-gray-900"><?= number_format(min($page * $perPage, $total)) ?></span>
147
+ of
148
+ <span class="font-semibold text-gray-900"><?= number_format($total) ?></span>
149
+ results for "<span class="font-semibold text-gray-900"><?= htmlspecialchars($query) ?></span>"
150
+ <?php else: ?>
151
+ No results found for "<span class="font-semibold text-gray-900"><?= htmlspecialchars($query) ?></span>"
152
+ <?php endif; ?>
153
+ <?php if ($collection): ?>
154
+ in <span class="font-semibold"><?= htmlspecialchars($collectionNames[$collection] ?? $collection) ?></span>
155
+ <?php endif; ?>
156
+ </p>
157
+ </div>
158
+
159
+ <?php if (!empty($results)): ?>
160
+ <div class="space-y-3">
161
+ <?php foreach ($results as $result): ?>
162
+ <?php
163
+ $docId = $result['document_id'] ?? 0;
164
+ $docName = $result['document_name'] ?? basename($result['file_path'] ?? 'Unknown');
165
+ $section = $result['source_section'] ?? '';
166
+ $sectionName = $collectionNames[$section] ?? ucwords(str_replace('_', ' ', $section));
167
+ $badgeColor = $collectionBadgeColors[$section] ?? 'bg-gray-100 text-gray-700';
168
+ $pageNum = $result['page_number'] ?? null;
169
+ $snippet = $result['snippet'] ?? '';
170
+ ?>
171
+ <div class="bg-white rounded-lg shadow-sm border border-gray-200 hover:shadow-md transition-shadow overflow-hidden">
172
+ <div class="p-3.5">
173
+ <!-- Document Name -->
174
+ <div class="flex flex-wrap items-center gap-1.5 mb-1.5">
175
+ <a href="/document/<?= (int)$docId ?><?= $pageNum ? '#page=' . (int)$pageNum : '' ?>"
176
+ class="text-sm font-semibold text-blue-600 hover:text-blue-800 transition-colors">
177
+ <?= htmlspecialchars($docName) ?>
178
+ </a>
179
+ <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium <?= $badgeColor ?>">
180
+ <?= htmlspecialchars($sectionName) ?>
181
+ </span>
182
+ <?php if ($pageNum !== null): ?>
183
+ <span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 text-gray-600">
184
+ p.<?= (int)$pageNum ?>
185
+ </span>
186
+ <?php endif; ?>
187
+ </div>
188
+
189
+ <!-- Snippet -->
190
+ <?php if ($snippet): ?>
191
+ <div class="text-xs text-gray-700 leading-relaxed line-clamp-3">
192
+ <?= $snippet ?>
193
+ </div>
194
+ <?php endif; ?>
195
+
196
+ <!-- Action Link -->
197
+ <div class="mt-2">
198
+ <a href="/document/<?= (int)$docId ?><?= $pageNum ? '#page=' . (int)$pageNum : '' ?>"
199
+ class="inline-flex items-center text-xs font-medium text-blue-600 hover:text-blue-800 transition-colors group">
200
+ View
201
+ <svg class="ml-1 h-3 w-3 group-hover:translate-x-0.5 transition-transform" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
202
+ <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />
203
+ </svg>
204
+ </a>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ <?php endforeach; ?>
209
+ </div>
210
+
211
+ <!-- Pagination -->
212
+ <?php
213
+ $currentPage = $page;
214
+ $paginationParams = 'q=' . urlencode($query);
215
+ if ($collection) {
216
+ $paginationParams .= '&collection=' . urlencode($collection);
217
+ }
218
+ $baseUrl = '/search?' . $paginationParams;
219
+ include __DIR__ . '/partials/pagination.php';
220
+ ?>
221
+
222
+ <?php else: ?>
223
+ <!-- No Results -->
224
+ <div class="text-center py-10 bg-white rounded-lg border border-gray-200">
225
+ <svg class="mx-auto h-8 w-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
226
+ <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
227
+ </svg>
228
+ <h3 class="mt-3 text-sm font-medium text-gray-900">No results found</h3>
229
+ <p class="mt-1 text-xs text-gray-500 max-w-md mx-auto">
230
+ Try adjusting your search terms or removing collection filters.
231
+ </p>
232
+ </div>
233
+ <?php endif; ?>
234
+
235
+ <?php else: ?>
236
+ <!-- Initial state: no query yet -->
237
+ <div class="text-center py-10">
238
+ <svg class="mx-auto h-10 w-10 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1">
239
+ <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
240
+ </svg>
241
+ <h3 class="mt-3 text-sm font-medium text-gray-700">Enter a search query</h3>
242
+ <p class="mt-1 text-xs text-gray-500">Search across all collections by text content, entity names, or document titles.</p>
243
+ </div>
244
+ <?php endif; ?>
245
+
246
+ <?php
247
+ $content = ob_get_clean();
248
+ include __DIR__ . '/layout.php';
249
+ ?>