]> git.plutz.net Git - shellwiki/blobdiff - handlers/40_search.sh
define search function as macro
[shellwiki] / handlers / 40_search.sh
index 3db8987164a867273aab6de87d504395aa838166..3661f954b7e07c6665f419484bb00c2edb9e7a90 100644 (file)
@@ -1,40 +1,21 @@
 #!/bin/sh
 
-[ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
-
-. "$_EXEC/cgilite/storage.sh"
-
-I="$_DATA/index"
-words="$(GET q |tr '] \t\n\r!\"#'\''()*+,./:;<=>?\\^_`{|}~[-' ' ')"
+# 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
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-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
+[ "$SEARCH_INDEX" != true ] && return 1
+[ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
 
-    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
+theme_page "/[wiki]/search/" "$(page_title "/[wiki]/search/")"
+return 0