]> git.plutz.net Git - shellwiki/commitdiff
reindex after tree movement, bugfix in search filtering, improved search weighting
authorPaul Hänsch <paul@plutz.net>
Mon, 25 Sep 2023 14:05:00 +0000 (16:05 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 25 Sep 2023 14:05:00 +0000 (16:05 +0200)
handlers/40_search.sh
handlers/60_move_rename_delete.sh
index.cgi
parsers/40_indexer.sh
searchindex.sh

index 5d0b1f698d14987c7d79843557669a5b8adc3925..90840603cd6ec7e1881b197f92994d2bbd4e3882 100644 (file)
@@ -14,6 +14,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+[ "$SEARCH_INDEX" != true ] && return 1
 [ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
 
 . "$_EXEC/cgilite/storage.sh"
@@ -35,14 +36,14 @@ for w in ${words}; do
 
   while read date doc freq num total; do
     P="$_DATA/pages$(UNSTRING "$doc")"
-    d="$(stat -c %Y -- "$P/#index.flag")"
-    [ "$d" -gt "$date" ] && continue
+    d="$(stat -c %Y -- "$P/#index.flag" 2>&-)"
+    [ "$d" -le "$date" ] 2>&- || continue
 
     printf '%s %f\n' "$doc" "$freq"
   done <"$I/$w"
 done \
 | awk '
-      { cnt[$1]++; weight[$1] = weight[$1] ? weight[$1] * $2 : $2; }
+      { cnt[$1]++; weight[$1] = weight[$1] ? weight[$1] + $2 : $2; }
   END { m = 0; for (d in cnt) m = ( m < cnt[d] ) ? cnt[d] : m;
         for (d in cnt) if ( cnt[d] == m ) printf "%f   %s\n", weight[d], d;
       }
index 749affcfdd88fa31c0021fb1c924bcd2c617f843..49651a29d9510255d26ae8662ed5492beb85b39e 100755 (executable)
@@ -165,15 +165,20 @@ if [ "$action" = rename -a "$newname" ]; then
     printf 'Refresh: %i\r\n' 4
     theme_error 403
     return 0
-  elif [ "$REV_PAGES" = true ]; then
+  fi
+  if [ "$REV_PAGES" = true ]; then
     git -C "$_DATA" mv "pages/$oldname" "pages/$newname"
     git -C "$_DATA" commit -m 'Page # '"$oldname"' # renamed to # '"$newname"' # by user @ '"$USER_NAME"' @' \
         -- "pages/$oldname" "pages/$newname"
-    REDIRECT "$_BASE${newname}"
   else
     mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname"
-    REDIRECT "$_BASE${newname}"
   fi
+  if [ "$SEARCH_INDEX" = true ]; then
+    find "$_DATA/pages/$newname" -name "#index.flag" -delete
+    ( "$_EXEC/searchindex.sh" index --location "$newname" & ) &
+  fi
+  REDIRECT "$_BASE${newname}"
+
 elif [ "$action" = move -a "$newlocation" ]; then
   oldname="${PATH_INFO%\[*\]}"
   newlocation="$(PATH "$newlocation")"
@@ -194,15 +199,20 @@ elif [ "$action" = move -a "$newlocation" ]; then
     printf 'Refresh: %i\r\n' 4
     theme_error 403
     return 0
-  elif [ "$REV_PAGES" = true ]; then
+  fi
+  if [ "$REV_PAGES" = true ]; then
     git -C "$_DATA" mv "pages/${oldname}" "pages/${newname}"
     git -C "$_DATA" commit -m 'Page # '"$oldname"' # moved to # '"$newname"' # by user @ '"$USER_NAME"' @' \
         -- "pages/${oldname}" "pages/${newname}"
-    REDIRECT "$_BASE${newname}"
   else
     mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname"
-    REDIRECT "$_BASE${newname}"
   fi
+  if [ "$SEARCH_INDEX" = true ]; then
+    find "$_DATA/pages/$newname" -name "#index.flag" -delete
+    ( "$_EXEC/searchindex.sh" index --location "$newname" & ) &
+  fi
+  REDIRECT "$_BASE${newname}"
+
 elif [ "$action" = delete ]; then
   oldname="${PATH_INFO%\[*\]}"
   if ! acl_write "$oldname"; then
index a426e0e7ec9db5b136d5f7da90ae265e88b09bf4..79e5e00ee4b670445f7af9d901ffbf2bfb968e6f 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -23,6 +23,7 @@
 export REV_PAGES=${REV_PAGES:-true}
 export REV_ATTACHMENTS=${REV_ATTACHMENTS:-false}
 export WIKI_THEME="${WIKI_THEME:-default}"
+export SEARCH_INDEX="${SEARCH_INDEX:-true}"
 
 which git >/dev/null || REV_PAGES=false
 [ "$REV_PAGES" != true ] && REV_ATTACHMENTS=false
@@ -46,12 +47,15 @@ if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then
   cat >"$_DATA/.gitignore" <<-EOF
        users.db
        serverkey
+       tags/
+       index/
        **/#cache/
-       **/#page.lock
+       **/#page.md.lock
        **/#page.*.cache
        **/#page.*.cache.*
        **/#page:*.*.cache
        **/#page:*.*.cache.*
+       **/#index.flag
        EOF
   [ "$REV_ATTACHMENTS" != true ] \
   && printf '**/#attachments/\n' >>"$_DATA/.gitignore"
index 7190b0b84f02c6a62f3a91b83f8887b767edac2f..c26584aeb101a34f008b83434446c4a9692273f1 100755 (executable)
@@ -16,7 +16,9 @@
 
 DOC="${PATH_INFO%/}/" P="$_DATA/pages${DOC}" I="$_DATA/index/"
 
-if [ -f "$P/#index.flag" -a ! "$P/#page.md" -nt "$P/#index.flag" ] || [ ! -d "$P" ]; then
+if [ "$SEARCH_INDEX" != true ] || [ ! -d "$P" ] || \
+   [ -f "$P/#index.flag" -a ! "$P/#page.md" -nt "$P/#index.flag" ]
+then
   cat
   exit 0
 fi
index 66f2704e97472657c7b1c5e97f53fd34043e6e24..526877dc7de0ffc2f540e39fe3226d06b5a12f7a 100755 (executable)
@@ -14,7 +14,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-export _EXEC="${0%/*}/" _DATA="."
+export _EXEC="${_EXEC:-${0%/*}/}" _DATA="${_DATA:-.}"
 verb="" v=0 cmd="" force="" location=""
 
 help() {
@@ -59,14 +59,15 @@ help() {
        Options:
 
        --exec INSTALL_DIR
-           Point to the location of your shellwiki installation. This will
-           default to the path at which the script is called, if it can be
-           determined.
+           Point to the location of your shellwiki installation. Without
+           this optin, the location will be read from the environments
+           variable "\$_EXEC", or will default to the path at which the
+           script is called, if it can be determined.
 
        --data SITE_DIR
            Point to the location of your site installation. I.e. the directory
-           containing your "pages/" and "index/" dir. Defaults to working
-           directory.
+           containing your "pages/" and "index/" dir. Defaults to the
+           environment variable "\$_DATA" or the working directory.
 
        --force
            Add pages to index even if they seem to be indexed already.