X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/fa30f71a6ab727c90e0b600582f9944dfaa1ca89..ead24d57321f965db99178336e9a72c03c966bd1:/search.php diff --git a/search.php b/search.php index e1da846..5bd03bb 100644 --- a/search.php +++ b/search.php @@ -1,10 +1,31 @@ $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 ($Page) { + $row = preg_replace('{(?:^|/)index\.html$}', '', $row); + return similar_text($row, $Page) - strlen($row) / 8; + }, $ls)); + arsort($ls); + + # prepend best match, replace unless duplicate + array_unshift($results, key($ls)); + $results = array_unique($results); + array_splice($results, $limit); +} -if (!$results) { +elseif (!$results) { $results = ['index.html']; }