_INDEX="${PATH_INFO#/}" _INDEX="${_INDEX%%/*}"
_records="${_DATA}/${_INDEX}/_0_DOCS"
+if [ "${INDEX}" -a ! -d "${_DATA}/${_INDEX}" ]; then
+ printf '%s\r\n' "Status: 404 Not Found" ""
+ exit 0
+elif authlist="$(DBM "${_DATA}/auth.db" get "${_INDEX}" )"; then
+ auth="$(HEADER Authorization)" auth="${auth#Basic }"
+ for a in $authlist deny; do
+ [ "$auth" = "$a" ] && break
+ done
+ if [ "$a" = "deny" -o ! "$auth" ]; then
+ printf '%s\r\n' "Status: 401 Unauthorized" \
+ "WWW-Authenticate: Basic realm=\"Rigid Find\"" "" \
+ | debug
+ exit 0
+ fi
+ unset a auth authlist
+fi
+
if [ "$REQUEST_METHOD" = "PUT" ]; then
_doc="${PATH_INFO#"/${_INDEX}/_doc"}"
exit 0
elif [ "$REQUEST_METHOD" = "POST" ]; then
- J="$(json_load "$(head -c "${CONTENT_LENGTH:-0}")")"
+ J="$(json_load "$(head -c "${CONTENT_LENGTH:-0}" |debug)")"
J="$(json_get "$J" query.bool.must.bool.should)"
words="$(
json_get "$(UNSTRING "$j")" match_phrase_prefix.content
done 2>/dev/null
)"
+ debug "Search words: $words"
results="@ $(
search "${_DATA}/${_INDEX}" $words \
| while read -r score id source; do
+ debug "Hit: $id $score"
S="$(DB2 "" set _index str:"${_INDEX}")"
S="$(DB2 "$S" set _id str:"$(UNSTRING "${id#/}")")"
S="$(DB2 "$S" set _score num:"$score")"
&& ctype="${accept}" || ctype="application/json"
cat <<-EOF
- HTTP/1.1 200 OK\r
+ Status: 200 OK\r
X-elastic-product: Elasticsearch\r
content-type: ${ctype}\r
\r
&& ctype="${accept}" || ctype="application/json"
cat <<-EOF
- HTTP/1.1 200 OK\r
+ Status: 200 OK\r
X-elastic-product: Elasticsearch\r
content-type: ${ctype}\r
\r