meili scripting

master
Bel LaPointe 2021-12-15 15:35:30 -07:00
parent 1e39a34c54
commit b3d26a88c2
4 changed files with 54 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
**/*.sw*
**/__pycache__
/meilisearch
/.meilisearch
/scraped
/data.ms

View File

@ -1,10 +1,12 @@
#! /bin/bash
if [ ! -f ./meilisearch ]; then
if [ ! -f ./.meilisearch ]; then
echo "https://docs.meilisearch.com/learn/getting_started/installation.html#configuration-options"
curl -L https://install.meilisearch.com | sh
mv ./meilisearch ./.meilisearch
fi
args=("$@")
if [ "${#args[@]}" == 0 ]; then
args=(--db-path $PWD/data.ms --http-addr 0.0.0.0:7700)
fi
exec ./meilisearch "${args[@]}"
exec ./.meilisearch "${args[@]}"

View File

49
to_meili.sh Normal file
View File

@ -0,0 +1,49 @@
#! /bin/bash
export MEILI="${MEILI:-"127.0.0.1:7700"}"
export SCRAPED="${SCRAPED:-"./scraped"}"
curl() {
$(which curl) -Ss -L -H 'Content-Type: application/json' "$@"
echo
}
log() {
echo "> $(date) > $*" >&2
}
meili_index() {
log index
curl "$MEILI"/indexes/scraped
}
meili_query() {
log query: "$*"
curl "$MEILI"/indexes/scraped/search -X POST -d "$(goprintf '{%q: %q}' "q" "$*")"
}
meili_queue() {
log queue
curl "$MEILI"/indexes/scraped/updates
}
scraped_to_meili() {
find "$SCRAPED" -type f \
| sort \
| while read -r md_path; do
id="$(echo "$md_path" | sed 's/[^a-zA-Z0-9_-]/_/g')"
content="$(cat "$md_path")"
echo md_path=$md_path, content=${#content}
curl -sS \
"$MEILI"/indexes/scraped/documents \
-X POST \
-d "$(
goprintf '[{%q: %q, %q: %q}]' \
"id" \
"$id" \
"content" \
"$content"
)"
break
done
}