X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=handlers%2F40_search.sh;h=90840603cd6ec7e1881b197f92994d2bbd4e3882;hb=a07eac0983626728785ad03cb767351a013e27b9;hp=6ac6dce6720066e71a2adb419f29dc633674f417;hpb=77277d37a63dd39f767cc7bbf5934a8381a0dd3c;p=shellwiki diff --git a/handlers/40_search.sh b/handlers/40_search.sh index 6ac6dce..9084060 100644 --- a/handlers/40_search.sh +++ b/handlers/40_search.sh @@ -1,5 +1,20 @@ #!/bin/sh +# Copyright 2023 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. + +[ "$SEARCH_INDEX" != true ] && return 1 [ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1 . "$_EXEC/cgilite/storage.sh" @@ -21,14 +36,14 @@ for w in ${words}; do while read date doc freq num total; do P="$_DATA/pages$(UNSTRING "$doc")" - d="$(stat -c %Y -- "$P/#index.flag")" - [ "$d" -gt "$date" ] && continue + 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; } + { 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; }