]> git.plutz.net Git - shellwiki/blobdiff - handlers/40_search.sh
search form on result page
[shellwiki] / handlers / 40_search.sh
index 3db8987164a867273aab6de87d504395aa838166..1d37989eb4c760679e63dd096a6b9e68dbf5153b 100644 (file)
@@ -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"
@@ -32,7 +41,10 @@ done \
 done \
 | theme_page - <<-EOF
        <article>
-         <h1>$(_ "Search results:")</h1>
+         <form method=GET>
+         <h1>$(_ "Search results")</h1>
+            <input class="search" name="q" placeholder="$(_ Search)" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
+         </form>
          <ol class="searchresults">
            $(cat)
          </ol>