X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=parsers%2F40_indexer.sh;h=7190b0b84f02c6a62f3a91b83f8887b767edac2f;hb=4e89a8d6ab962a2582f78fbf47b1f49c735662cd;hp=d5783f4ea9c8e79cb78dbf706ab75888ec0fd78f;hpb=feca7d3f5bff6cd8b1437adb95686a77ab8e9367;p=shellwiki diff --git a/parsers/40_indexer.sh b/parsers/40_indexer.sh index d5783f4..7190b0b 100755 --- a/parsers/40_indexer.sh +++ b/parsers/40_indexer.sh @@ -14,10 +14,9 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -DOC="${PATH_INFO%/}/" DOC="${DOC%/\[*\]/}" DOC="${DOC%/}/" -P="$_DATA/pages${DOC}" I="$_DATA/index/" +DOC="${PATH_INFO%/}/" P="$_DATA/pages${DOC}" I="$_DATA/index/" -if [ -f "$P/#index.flag" -a ! "$P/#page.md" -nt "$P/#index.flag" ]; then +if [ -f "$P/#index.flag" -a ! "$P/#page.md" -nt "$P/#index.flag" ] || [ ! -d "$P" ]; then cat exit 0 fi @@ -26,7 +25,7 @@ fi exec 3>&1 -touch "$P/#index.flag" +touch -d "@$_DATE" "$P/#index.flag" mkdir -p "$I" { cat; printf \\n; } \ @@ -35,26 +34,23 @@ mkdir -p "$I" printf '%s\n' "$line" done \ | awk ' - BEGIN { FS = "[] \t\n\r!\"#'\''()*+,./:;<=>?\\^_`{|}~[-]+" } - { for (n = 1; n <= NF; n++) if ( $n != "" ) { words[tolower($n)]++; total++; } } + 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 != "" && length($n) <= 128 ) { + words[tolower($n)]++; total++; + } } } END { for (w in words) printf "%i %i %f %s\n", words[w], total, words[w] / total, w; } ' \ -| while read num total freq word; do +| while read -r num total freq word; do [ "$word" ] || continue - F="$I/$word" - L="$(STRING "$DOC")" - - if LOCK "$F"; then - touch "$F" - { while read d l f n t; do - [ "$l" = "$L" ] \ - || printf "%i %s %f %i %i\n" \ - "$d" "$l" "$f" "$n" "$t" - done <"$F" - printf "%i %s %f %i %i\n" \ - "$_DATE" "$L" "$freq" "$num" "$total" - } >"$F.$$" - mv -- "$F.$$" "$F" - RELEASE "$F" - fi + printf "%i %s %f %i %i\n" \ + "$_DATE" "$(STRING "$DOC")" \ + "$freq" "$num" "$total" \ + >>"$I/$word" done