--- /dev/null
+#!/bin/sh
+
+[ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
+
+. "$_EXEC/cgilite/storage.sh"
+
+I="$_DATA/index"
+words="$(GET q |tr '] \t\n\r!\"#'\''()*+,./:;<=>?\\^_`{|}~[-' ' ')"
+
+for w in ${words}; do
+ [ ! -f "$I/$w" ] && continue
+
+ while read date doc freq num total; do
+ P="$_DATA/pages$(UNSTRING "$doc")"
+ d="$(stat -c %Y -- "$P/#page.md")"
+ [ "$d" -gt "$date" ] && continue
+
+ printf '%s %f\n' "$doc" "$freq"
+ done <"$I/$w"
+done \
+| awk '
+ { cnt[$1]++; weight[$1] = weight[$1] ? weight[$1] * $2 : $2; }
+ END { m = 0; for (d in cnt) m = ( m < cnt[d] ) ? cnt[d] : m;
+ for (d in cnt) if ( cnt[d] == m ) printf "%f %s\n", weight[d], d;
+ }
+' \
+| sort -nr \
+| while read freq doc; do
+ page="$(UNSTRING "$doc")"
+ acl_read "$page" || continue
+ printf '<li><a href="%s">%s</a></li>' "$(URL "$page")" "$(HTML "$page")"
+done \
+| theme_page - <<-EOF
+ <article>
+ <h1>$(_ "Search results:")</h1>
+ <ol class="searchresults">
+ $(cat)
+ </ol>
+ </article>
+ EOF