meili scripting
parent
1e39a34c54
commit
b3d26a88c2
|
|
@ -1,5 +1,5 @@
|
||||||
**/*.sw*
|
**/*.sw*
|
||||||
**/__pycache__
|
**/__pycache__
|
||||||
/meilisearch
|
/.meilisearch
|
||||||
/scraped
|
/scraped
|
||||||
/data.ms
|
/data.ms
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#! /bin/bash
|
#! /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
|
curl -L https://install.meilisearch.com | sh
|
||||||
|
mv ./meilisearch ./.meilisearch
|
||||||
fi
|
fi
|
||||||
args=("$@")
|
args=("$@")
|
||||||
if [ "${#args[@]}" == 0 ]; then
|
if [ "${#args[@]}" == 0 ]; then
|
||||||
args=(--db-path $PWD/data.ms --http-addr 0.0.0.0:7700)
|
args=(--db-path $PWD/data.ms --http-addr 0.0.0.0:7700)
|
||||||
fi
|
fi
|
||||||
exec ./meilisearch "${args[@]}"
|
exec ./.meilisearch "${args[@]}"
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue