X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=macros%2Fsearch;h=f72fd0b7112a6d500e92755ae6011bc2dd771551;hb=2d69d91ccf6218c1c80fe3ee02a87b601e945282;hp=b3d06e85a86fbc33274b48b298b4af9b926bd48b;hpb=20c6ce6a3de621383d1b6d985757366590722005;p=shellwiki diff --git a/macros/search b/macros/search index b3d06e8..f72fd0b 100755 --- a/macros/search +++ b/macros/search @@ -25,7 +25,7 @@ I="$_DATA/index" _(){ printf %s\\n "$*"; } [ "${LANGUAGE}" -a -r "${_EXEC}/l10n/${LANGUAGE}.sh" ] && . "${_EXEC}/l10n/${LANGUAGE}.sh" -show_form=true show_hits='' action='' +show_form=true show_hits='' action='' query='' set -- "$@" -- while [ $# -gt 0 ]; do case $1 in @@ -41,6 +41,8 @@ while [ $# -gt 0 ]; do case $1 in *) set -- "$@" "$1"; shift 1;; esac; done +[ $@ -gt 0 ] && query="$*" || query="$(GET q)" + searchteaser() { local file="$1" words db3_data local w l nc nl hits mhits cont mcont @@ -79,19 +81,23 @@ elif [ ! "$action" ]; then fi if [ "${show_form}" = true ]; then - printf '' "$action" "$(_ Search)" "$([ "$show_hits" = true ] && GET q |HTML)" "$(_ Search)" + cat <<-EOF + + EOF fi if [ "${show_hits}" = true ]; then { read tags; read ntags; read words; } <<-EOF - $(GET q | awk ' + $(printf %s\\n "${query}" | 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]')"')+"; + 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]')"')+"; + FS = "([] \\t\\n\\r\"'\''()*+,./:;<=>?\\\\^`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+"; fi } { t=0; for (n = 1; n <= NF; n++) if ($n ~ /#[[:alnum:]_]+/) tags[t++] = toupper($n); @@ -99,7 +105,7 @@ if [ "${show_hits}" = true ]; then t=0; for (n = 1; n <= NF; n++) if ($n !~ /![[:alnum:]_]+/) words[t++] = tolower($n); for (t in tags) { sub(/^#/, "", tags[t]); printf "%s ", tags[t]; } print ""; for (t in ntags) { sub(/^!/, "", ntags[t]); printf "%s ", ntags[t]; } print ""; - for (t in words) { sub(/^[!#]/, "", words[t]); printf "%s ", words[t]; } print ""; + for (t in words) { gsub(/[!#_ ]+/, " ", words[t]); printf "%s ", words[t]; } print ""; } ') EOF