git.shiar.nl
/
minimedit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
search: dedicated page with query form
[minimedit.git]
/
search.php
diff --git
a/search.php
b/search.php
index 5bd03bb3d464f882e8e6b908157fe5ab4b843672..2f093c9d8dacf517747298a11d686be5a8895873 100644
(file)
--- a/
search.php
+++ b/
search.php
@@
-1,8
+1,11
@@
<?php
<?php
-$limit = 10;
+$limit =
@$Place['limit'] ?:
10;
$path = ' '.escapeshellarg('*.html');
$path = ' '.escapeshellarg('*.html');
+$query = @$_REQUEST['q'] ?: $Args ?: $Page;
-$cmd = "git grep -li -- ".escapeshellarg($Page).$path;
+if (!trim($query, '/')) return;
+
+$cmd = "git grep -li -- ".escapeshellarg($query).$path;
exec($cmd, $results);
if (count($results) > $limit) {
shuffle($results);
exec($cmd, $results);
if (count($results) > $limit) {
shuffle($results);
@@
-13,9
+16,9
@@
$cmd = "git ls-files -- $path";
exec($cmd, $ls);
if ($ls) {
# order files by similarity to query
exec($cmd, $ls);
if ($ls) {
# order files by similarity to query
- $ls = array_combine($ls, array_map(function ($row) use ($
Page
) {
+ $ls = array_combine($ls, array_map(function ($row) use ($
query
) {
$row = preg_replace('{(?:^|/)index\.html$}', '', $row);
$row = preg_replace('{(?:^|/)index\.html$}', '', $row);
- return similar_text($row, $
Page
) - strlen($row) / 8;
+ return similar_text($row, $
query
) - strlen($row) / 8;
}, $ls));
arsort($ls);
}, $ls));
arsort($ls);
@@
-29,6
+32,13
@@
elseif (!$results) {
$results = ['index.html'];
}
$results = ['index.html'];
}
+if (isset($Place['verbose'])) {
+ printf("<p>%s gevonden voor <q>%s</q>:</p>\n",
+ $results ? count($results).' resultaten' : 'Niets',
+ htmlspecialchars($query)
+ );
+}
+
require_once('nieuws.inc.php');
print '<ul>';
foreach ($results as $result) {
require_once('nieuws.inc.php');
print '<ul>';
foreach ($results as $result) {