Skip to content

Commit 9619558

Browse files
carlbennettclaude
andcommitted
Implement SearchPlain view
Replace TODO stub with plain text output grouped by result type (comments, documents, news posts, packets, servers, users). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 105190f commit 9619558

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

src/Views/Search/SearchPlain.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
namespace BNETDocs\Views\Search;
44

5+
use \BNETDocs\Libraries\Comment;
6+
use \BNETDocs\Libraries\Document;
7+
use \BNETDocs\Libraries\News\Post as NewsPost;
8+
use \BNETDocs\Libraries\Packet\Packet;
9+
use \BNETDocs\Libraries\Server\Server;
10+
use \BNETDocs\Libraries\User\User;
11+
512
class SearchPlain extends \BNETDocs\Views\Base\Plain
613
{
714
public static function invoke(\BNETDocs\Interfaces\Model $model): void
@@ -11,7 +18,63 @@ public static function invoke(\BNETDocs\Interfaces\Model $model): void
1118
throw new \BNETDocs\Exceptions\InvalidModelException($model);
1219
}
1320

14-
echo 'TODO';
1521
$model->_responseHeaders['Content-Type'] = self::mimeType();
22+
23+
$q = $model->user_input ?? '';
24+
$results = $model->results;
25+
26+
if (!$results || $results->isEmpty())
27+
{
28+
printf("No results for: %s\n", $q);
29+
return;
30+
}
31+
32+
printf("Search Results\n==============\nQuery: %s\n\n", $q);
33+
34+
$sections = [
35+
'Comments' => $results->getComments(),
36+
'Documents' => $results->getDocuments(),
37+
'News Posts' => $results->getNewsPosts(),
38+
'Packets' => $results->getPackets(),
39+
'Servers' => $results->getServers(),
40+
'Users' => $results->getUsers(),
41+
];
42+
43+
foreach ($sections as $label => $items)
44+
{
45+
if (empty($items)) continue;
46+
47+
$heading = sprintf('%s (%d)', $label, count($items));
48+
printf("%s\n%s\n", $heading, str_repeat('-', strlen($heading)));
49+
50+
foreach ($items as $item)
51+
{
52+
switch (true)
53+
{
54+
case $item instanceof Comment:
55+
printf("- Comment #%d\n", $item->getId());
56+
break;
57+
case $item instanceof Document:
58+
printf("- %s <%s>\n", $item->getTitle(), $item->getURI());
59+
break;
60+
case $item instanceof NewsPost:
61+
printf("- %s <%s>\n", $item->getTitle(), $item->getURI());
62+
break;
63+
case $item instanceof Packet:
64+
printf("- %s <%s>\n", $item->getLabel(), $item->getURI());
65+
break;
66+
case $item instanceof Server:
67+
printf("- %s <%s>\n", $item->getLabel(), $item->getURI());
68+
break;
69+
case $item instanceof User:
70+
printf("- %s <%s>\n", $item->getName(), $item->getURI());
71+
break;
72+
default:
73+
printf("- ID %d\n", $item->getId());
74+
}
75+
}
76+
77+
echo "\n";
78+
}
1679
}
1780
}

0 commit comments

Comments
 (0)