From 65b04e000d563f2347370cbf3e1e01cf2af0a168 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 25 Sep 2023 16:05:00 +0200 Subject: [PATCH] reindex after tree movement, bugfix in search filtering, improved search weighting --- handlers/40_search.sh | 7 ++++--- handlers/60_move_rename_delete.sh | 22 ++++++++++++++++------ index.cgi | 6 +++++- parsers/40_indexer.sh | 4 +++- searchindex.sh | 13 +++++++------ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/handlers/40_search.sh b/handlers/40_search.sh index 5d0b1f6..9084060 100644 --- a/handlers/40_search.sh +++ b/handlers/40_search.sh @@ -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; } diff --git a/handlers/60_move_rename_delete.sh b/handlers/60_move_rename_delete.sh index 749affc..49651a2 100755 --- a/handlers/60_move_rename_delete.sh +++ b/handlers/60_move_rename_delete.sh @@ -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 diff --git a/index.cgi b/index.cgi index a426e0e..79e5e00 100755 --- 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" diff --git a/parsers/40_indexer.sh b/parsers/40_indexer.sh index 7190b0b..c26584a 100755 --- a/parsers/40_indexer.sh +++ b/parsers/40_indexer.sh @@ -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 diff --git a/searchindex.sh b/searchindex.sh index 66f2704..526877d 100755 --- a/searchindex.sh +++ b/searchindex.sh @@ -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. -- 2.39.2