#!/bin/sh
-[ "${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); }
-')"
+# 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/#index.flag")"
- [ "$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>
- <form method=GET>
- <h1>$(_ "Search results")</h1>
- <input class="search" name="q" placeholder="$(_ Search)" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
- </form>
- <ol class="searchresults">
- $(cat)
- </ol>
- </article>
- EOF
+theme_page "/[wiki]/search/" "$(page_title "/[wiki]/search/")"
+return 0