From: Paul Hänsch Date: Fri, 22 Sep 2023 08:07:31 +0000 (+0200) Subject: search handler X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=b45089e38287dd6da2cab48069cae40805f98da3;p=shellwiki search handler --- diff --git a/handlers/40_search.sh b/handlers/40_search.sh new file mode 100644 index 0000000..3db8987 --- /dev/null +++ b/handlers/40_search.sh @@ -0,0 +1,40 @@ +#!/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 '
  • %s
  • ' "$(URL "$page")" "$(HTML "$page")" +done \ +| theme_page - <<-EOF +
    +

    $(_ "Search results:")

    +
      + $(cat) +
    +
    + EOF