Skip to content

Commit 7ca9458

Browse files
committed
feat: add simple search engine
1 parent b7c1db4 commit 7ca9458

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/index.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,19 @@ function getDeepUrlsFromArray(array $input_urls): array {
147147
*/
148148
function globalsearch(string $query, string $root_folder): array {
149149
$[end]$
150-
$[if `process.env.SEARCH === "true" && process.env.SEARCH_ENGINE === "regex"`]$
150+
$[if `process.env.SEARCH === "true" && (process.env.SEARCH_ENGINE === "regex" || process.env.SEARCH_ENGINE === "simple")`]$
151151
$rdit = new RecursiveDirectoryIterator($root_folder, RecursiveDirectoryIterator::SKIP_DOTS);
152152
$rit = new RecursiveIteratorIterator($rdit);
153153
$rit->setMaxDepth(${{`process.env.SEARCH_MAX_DEPTH`}}$);
154+
$[end]$
155+
$[if `process.env.SEARCH === "true" && process.env.SEARCH_ENGINE === "regex"`]$
154156
$found = new RegexIterator($rit, "/$query/", RecursiveRegexIterator::MATCH);
155157
$[end]$
158+
$[if `process.env.SEARCH === "true" && process.env.SEARCH_ENGINE === "simple"`]$
159+
$found = new CallbackFilterIterator($rit, function ($current) use ($query) {
160+
return str_contains($current->getFilename(), $query);
161+
});
162+
$[end]$
156163
$[if `process.env.SEARCH === "true" && process.env.SEARCH_ENGINE === "glob"`]$
157164
$found = new GlobIterator($root_folder . "/" . $query, FilesystemIterator::SKIP_DOTS);
158165
$[end]$
@@ -1058,6 +1065,7 @@ function getRelativeTimeString(date, lang = navigator.language) {
10581065
}
10591066
const search = async () => {
10601067
const search = document.querySelector('#search').value;
1068+
if (search.length === 0) return;
10611069
const api = await fetch(`${{`process.env.BASE_PATH ?? ''`}}$?q=${search}`).then((res) => res.json());
10621070
console.log(api.results)
10631071

0 commit comments

Comments
 (0)