]> git.plutz.net Git - shellwiki/blobdiff - parsers/40_indexer.sh
bugfix: prevent accidental index invalidation by getting doc path from pwd instead...
[shellwiki] / parsers / 40_indexer.sh
index 08060f1637ba6aa4b83a1d686fab601f09751ffd..d25aacfb82179c426abde0c4baea849e534e9090 100755 (executable)
 # 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%/}/" P="$_DATA/pages${DOC}" I="$_DATA/index/"
+P="$PWD" I="$_DATA/index/" _DATE=$((_DATE + 1))
 
-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/#index.flag" -ot "$P/#page.md" ]
+then
   cat
   exit 0
 fi
@@ -27,6 +29,7 @@ exec 3>&1
 
 touch -d "@$_DATE" "$P/#index.flag"
 mkdir -p "$I"
+DOC="$(STRING "${P#"$_DATA/pages"}")"
 
 { cat; printf \\n; } \
 | while IFS='' read -r line; do
@@ -49,20 +52,7 @@ done \
 ' \
 | 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" "$DOC" "$freq" "$num" "$total" \
+  >>"$I/$word"
 done