3 # Copyright 2023 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 [ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
19 . "$_EXEC/cgilite/storage.sh"
22 words="$( GET q | awk '
23 BEGIN { # Field separator FS should include punctuation, including Unicode Block U+2000 - U+206F
24 if ( length("¡") == 1 ) # Utf-8 aware AWK
25 FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
27 FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
30 { for (n = 1; n <= NF; n++) printf "%s ", tolower($n); }
34 [ ! -f "$I/$w" ] && continue
36 while read date doc freq num total; do
37 P="$_DATA/pages$(UNSTRING "$doc")"
38 d="$(stat -c %Y -- "$P/#index.flag")"
39 [ "$d" -gt "$date" ] && continue
41 printf '%s %f\n' "$doc" "$freq"
45 { cnt[$1]++; weight[$1] = weight[$1] ? weight[$1] * $2 : $2; }
46 END { m = 0; for (d in cnt) m = ( m < cnt[d] ) ? cnt[d] : m;
47 for (d in cnt) if ( cnt[d] == m ) printf "%f %s\n", weight[d], d;
51 | while read freq doc; do
52 page="$(UNSTRING "$doc")"
53 [ "${page%*/\[*\]/*}" != "$page" ] && continue
54 if [ "$LANGUAGE_DEFAULT" ]; then
55 [ -d "${_DATA}/pages/${page}/:${LANGUAGE}/" ] && continue
56 [ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue
58 acl_read "$page" || continue
61 | theme_search "${words% }"