]> git.plutz.net Git - rigidfind/blobdiff - index.cgi
bugfix: time calculation
[rigidfind] / index.cgi
index 50fb338aa1c0e7413664c3c44fd4e0b3090fe770..945d133985a5ddc242bc062a2ce1d39b280f762e 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,11 +1,13 @@
 #!/bin/sh
 
+read _DATE _date_n <<-EOF
+       $(date +"%s     %N")
+       EOF
+
 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
 . "${_EXEC:-${0%/*}}/cgilite/storage.sh"
 . "${_EXEC:-${0%/*}}/cgilite/json.sh"
 
-[ "$_DATE" ] || _DATE="$(date +%s)"
-
 debug "$REQUEST_METHOD $REQUEST_URI    $SERVER_PROTOCOL        $_DATE"
 
 ingest() {
@@ -217,7 +219,7 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then
   words="$(
     for j in $(DB2 "$J" iterate @); do
       json_get "$(UNSTRING "$j")" match_phrase_prefix.content
-    done 2>/dev/null
+    done 2>/dev/null |tr \\n ' '
   )"
   debug "Search words: $words"
 
@@ -234,17 +236,18 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then
   )"
   results="${results%  }"
 
+  t="$(( $(date +%s%N) - ${_DATE}${_date_n} ))"
+
   cat <<-EOF
        Status: 200 OK\r
        X-elastic-product: Elasticsearch\r
        Content-Type: application/vnd.elasticsearch+json;compatible-with=8\r
        \r
-       { "took":0,
+       { "took":$((t / 1000000)),
          "timed_out":false,
-         "_shards":{"total":1,"successful":1,"skipped":0,"failed":0},
          "hits": {
            "total":{"value": $(DB2 "$results" count @) ,"relation":"eq"},
-           "max_score": $(json_get "arr:$results" '[0]._score' 2>&- || printf 0),
+           "max_score": $(json_get "arr:$results" '[0]._score' 2>/dev/null || printf 0),
            "hits": $(json_dump "arr:$results")
          }
        }