X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/fa30f71a6ab727c90e0b600582f9944dfaa1ca89..73362ad67d9e983d7ab26c068e4d595069bf01ef:/search.php diff --git a/search.php b/search.php index e1da846..2f093c9 100644 --- a/search.php +++ b/search.php @@ -1,13 +1,44 @@ $limit) { + shuffle($results); + array_splice($results, $limit); +} + +$cmd = "git ls-files -- $path"; +exec($cmd, $ls); +if ($ls) { + # order files by similarity to query + $ls = array_combine($ls, array_map(function ($row) use ($query) { + $row = preg_replace('{(?:^|/)index\.html$}', '', $row); + return similar_text($row, $query) - strlen($row) / 8; + }, $ls)); + arsort($ls); -if (!$results) { + # prepend best match, replace unless duplicate + array_unshift($results, key($ls)); + $results = array_unique($results); + array_splice($results, $limit); +} + +elseif (!$results) { $results = ['index.html']; } +if (isset($Place['verbose'])) { + printf("

%s gevonden voor %s:

\n", + $results ? count($results).' resultaten' : 'Niets', + htmlspecialchars($query) + ); +} + require_once('nieuws.inc.php'); print '