]> git.plutz.net Git - shellwiki/blobdiff - handlers/40_search.sh
define search function as macro
[shellwiki] / handlers / 40_search.sh
index 90840603cd6ec7e1881b197f92994d2bbd4e3882..3661f954b7e07c6665f419484bb00c2edb9e7a90 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright 2023 Paul Hänsch
+# Copyright 2023, 2024 Paul Hänsch
 # 
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 [ "$SEARCH_INDEX" != true ] && return 1
 [ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
 
-. "$_EXEC/cgilite/storage.sh"
-
-I="$_DATA/index"
-words="$( GET q | awk '
-  BEGIN { # Field separator FS should include punctuation, including Unicode Block U+2000 - U+206F
-          if ( length("¡") == 1 )  # Utf-8 aware AWK
-          FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
-          else                     # UTF-8 Hack
-          FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
-          fi
-        }
-       { for (n = 1; n <= NF; n++) printf "%s  ", tolower($n); }
-')"
-
-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/#index.flag" 2>&-)"
-    [ "$d" -le "$date" ] 2>&- || 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")"
-  [ "${page%*/\[*\]/*}" != "$page" ] && continue
-  if [ "$LANGUAGE_DEFAULT" ]; then
-    [ -d "${_DATA}/pages/${page}/:${LANGUAGE}/" ] && continue
-    [ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue
-  fi
-  acl_read "$page" || continue
-  printf '%s\n' "$page"
-done \
-| theme_search "${words%       }"
+theme_page "/[wiki]/search/" "$(page_title "/[wiki]/search/")"
+return 0