summaryrefslogtreecommitdiffstats
path: root/_site/cgi-bin/find_glob.cgi
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-05-06 19:42:33 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-05-06 19:42:33 +0800
commit819bf74c2841fabdcc481e12e13615d48a92cb7f (patch)
tree00ba8c9105a96d88536f50f8ef96e838c04408e3 /_site/cgi-bin/find_glob.cgi
parenteddb76ad8c6e850c7e24f97ff27a185d48b104ee (diff)
downloadsite-search-bm-819bf74c2841fabdcc481e12e13615d48a92cb7f.tar.gz
Change directory structure and add benchmark runner.
Diffstat (limited to '_site/cgi-bin/find_glob.cgi')
-rw-r--r--_site/cgi-bin/find_glob.cgi147
1 files changed, 0 insertions, 147 deletions
diff --git a/_site/cgi-bin/find_glob.cgi b/_site/cgi-bin/find_glob.cgi
deleted file mode 100644
index db03bd5..0000000
--- a/_site/cgi-bin/find_glob.cgi
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Encode qw(decode_utf8);
-use HTML::Escape qw(escape_html);
-use Time::HiRes qw(gettimeofday tv_interval);
-use BSD::Resource;
-
-# 1. Start Benchmark Timer
-my $start_time = [gettimeofday];
-
-my $search_text = '';
-if ($ENV{QUERY_STRING} && $ENV{QUERY_STRING} =~ /^q=([^&]*)/) {
- $search_text = decode_utf8($1 // "");
- $search_text =~ s/\P{Print}//g;
- $search_text = substr($search_text, 0, 64);
- $search_text =~ s/^\s+|\s+$//g;
-}
-
-my @results;
-my $files_read = 0; # Track IO Activity
-
-my $start_dir = '../log';
-my @files = glob("$start_dir/*/index.html");
-
-foreach my $path (@files) {
- next if -l $path || ! -f $path;
-
- # Using :encoding(UTF-8) to handle the valid text files
- next unless open(my $fh, "<:encoding(UTF-8)", $path);
- $files_read++;
- my $html = do { local $/; <$fh> };
- close($fh);
-
- my ($text) = $html =~ m|<main>(.*?)</main>|is;
- $text =~ s|<[^>]+>| |g;
- $text =~ s|\s+| |g;
-
- next unless $text =~ /(.{0,40})(\Q$search_text\E)(.{0,40})/is;
- my ($before, $actual, $after) = ($1, $2, $3);
-
- $after =~ s/\s\S*$// if length($after) > 25;
- $before =~ s/^.*?\s// if length($before) > 25;
-
- if ($before =~ /\S/) {
- $before = ucfirst($before);
- } else {
- $before = "";
- $actual = ucfirst($actual);
- }
-
- my $safe_before = escape_html($before);
- my $safe_actual = escape_html($actual);
- my $safe_after = escape_html($after);
- my $snippet = "${safe_before}<b>${safe_actual}</b>${safe_after}...";
-
- my ($title) = $html =~ m|<title>(.*?)</title>|is;
- my $safe_title = escape_html($title || "No Title");
-
- push @results, {
- path => $path,
- title => $safe_title,
- snippet => $snippet
- };
-}
-
-# 2. Calculate Metrics
-my $end_time = [gettimeofday];
-my $elapsed = tv_interval($start_time, $end_time);
-
-my $rusage = getrusage();
-my $user_cpu = $rusage->utime;
-my $system_cpu = $rusage->stime;
-my $max_rss = $rusage->maxrss;
-
-# 3. Output
-print "Content-Type: text/html\n\n";
-
-my $list;
-if ($search_text eq '') {
- $list = "<p>Please enter a search term above.</p>";
-} elsif (@results == 0) {
- $list = "<p>No results found for \"<b>$search_text</b>\".</p>";
-} else {
- $list = "<ul>";
- foreach my $res (@results) {
- my $url = $res->{path};
- $list .= "<li><a href=\"/$url\">$res->{title}</a><br><small>$res->{snippet}</small></li>";
- }
- $list .= "</ul>";
-}
-
-my $safe_search_text = escape_html($search_text);
-my $year = (localtime)[5] + 1900;
-
-print <<"HTML";
-<!DOCTYPE html>
-<html lang="en-us">
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Search</title>
- <link rel="stylesheet" href="/assets/css/main.css">
- <link rel="stylesheet" href="/assets/css/skeleton.css">
-</head>
-<body>
- <div id="nav-container" class="container">
- <ul id="navlist" class="left">
- <li><a href="/" class="link-decor-none">hme</a></li>
- <li><a href="/log/" class="link-decor-none">log</a></li>
- <li><a href="/projects/" class="link-decor-none">poc</a></li>
- <li><a href="/about/" class="link-decor-none">abt</a></li>
- <li class="active"><a href="/cgi-bin/find.cgi" class="link-decor-none">sws</a></li>
- <li><a href="/feed.xml" class="link-decor-none">rss</a></li>
- </ul>
- </div>
- <main class="container" id="main">
- <div class="container">
- <h2>Search</h2>
- <form action="" method="GET">
- <input id="search-box" type="text" name="q" value="$safe_search_text">
- <input id="search-btn" type="submit" value="Search">
- </form>
- $list
-
- <div style="background: #f4f4f4; padding: 10px; border-radius: 5px; font-family: monospace; font-size: 0.85em; margin-top: 20px; border: 1px solid #ddd;">
- <strong>Performance Metrics:</strong><br>
- Total Time: @{[ sprintf("%.4f", $elapsed) ]} seconds<br>
- User CPU: $user_cpu s<br>
- System CPU: $system_cpu s<br>
- Peak RAM: $max_rss KB<br>
- Files Read: $files_read (IO Activity)
- </div>
- </div>
- </main>
- <div class="footer">
- <div class="container">
- <div class="twelve columns right container-2">
- <p id="footer-text">&copy; ASCIIMX - $year</p>
- </div>
- </div>
- </div>
-</body>
-</html>
-HTML
-