X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=handlers%2F40_search.sh;h=d198f220756319f457783e95af36d43d9114351e;hb=35c700335c55a0819e3582a77211e3cb280f48fe;hp=3db8987164a867273aab6de87d504395aa838166;hpb=b45089e38287dd6da2cab48069cae40805f98da3;p=shellwiki diff --git a/handlers/40_search.sh b/handlers/40_search.sh index 3db8987..d198f22 100644 --- a/handlers/40_search.sh +++ b/handlers/40_search.sh @@ -5,14 +5,23 @@ . "$_EXEC/cgilite/storage.sh" I="$_DATA/index" -words="$(GET q |tr '] \t\n\r!\"#'\''()*+,./:;<=>?\\^_`{|}~[-' ' ')" +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/#page.md")" + d="$(stat -c %Y -- "$P/#index.flag")" [ "$d" -gt "$date" ] && continue printf '%s %f\n' "$doc" "$freq" @@ -27,14 +36,12 @@ done \ | 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
  • ' "$(URL "$page")" "$(HTML "$page")" + printf '%s\n' "$page" done \ -| theme_page - <<-EOF -
    -

    $(_ "Search results:")

    -
      - $(cat) -
    -
    - EOF +| theme_search "${words% }"