From 6d62de4f9aa16fb129513fa38c60158bfde36f16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 19 Mar 2024 12:10:33 +0100 Subject: [PATCH] use tags (#positive and !negative) in search --- handlers/40_search.sh | 42 +++++++++++++++++++++++++++++++++++++++--- themes/default.sh | 2 +- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/handlers/40_search.sh b/handlers/40_search.sh index 1e33019..57117e3 100644 --- a/handlers/40_search.sh +++ b/handlers/40_search.sh @@ -21,15 +21,49 @@ . "$_EXEC/cgilite/db23.sh" I="$_DATA/index" +tags="$( 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++) if ($n ~ /#[[:alnum:]_]+/) { + sub(/^#/,"",$n) + printf "%s ", toupper($n); + } + } +')" + +ntags="$( 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++) if ($n ~ /![[:alnum:]_]+/) { + sub(/^!/,"",$n) + printf "%s ", toupper($n); + } + } +')" + 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]')"')+"; + 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 } - { for (n = 1; n <= NF; n++) printf "%s ", tolower($n); } + { for (n = 1; n <= NF; n++) if ($n !~ /![[:alnum:]_]+/) { + sub(/!/," ",$n) + printf "%s ", tolower($n); + } + } ')" searchteaser() { @@ -89,6 +123,8 @@ done \ [ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue fi acl_read "$page" || continue + has_tags "$page" $tags || continue + has_tag "$page" $ntags && continue printf '%s %s\n' "$doc" "$(searchteaser "$(mdfile "$page")" $words)" done \ | theme_search "${words% }" diff --git a/themes/default.sh b/themes/default.sh index 033dd7f..0f45c59 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -142,7 +142,7 @@ theme_search(){

$([ "$words" ] && _ "Search results" || _ "Search" )

    $(while read -r p t; do -- 2.39.2