forked from metabrainz/musicbrainz-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-search-indexes
executable file
·87 lines (71 loc) · 2.02 KB
/
delete-search-indexes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
set -e -u
# shellcheck source=admin/lib/common.inc.bash
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.inc.bash"
HELP=$(cat <<EOH
Usage: $SCRIPT_NAME all
or: $SCRIPT_NAME CORE... (for example: $SCRIPT_NAME artist release)
or: $SCRIPT_NAME --help
For each of MusicBrainz Solr cores/collections,
delete all indexed documents from Solr server.
Notes:
The Docker Compose service 'search' must be up.
EOH
)
# Parse arguments
if [ $# -eq 0 ]
then
echo >&2 "$SCRIPT_NAME: missing argument"
echo >&2 "Try '$SCRIPT_NAME --help' for usage."
exit 64 # EX_USAGE
fi
declare -A all_cores=(
[annotation]=1 [area]=1 [artist]=1 [cdstub]=1 [editor]=1 [event]=1
[instrument]=1 [label]=1 [place]=1 [recording]=1 [release]=1
[release-group]=1 [series]=1 [tag]=1 [url]=1 [work]=1
)
declare -a cores
if [[ $# -eq 1 && $1 =~ -*h(elp)? ]]
then
echo "$HELP"
exit 0 # EX_OK
elif [[ $# -eq 1 && $1 == all ]]
then
cores=( ${!all_cores[@]} )
else
cores=()
while [ $# -gt 0 ]
do
if [ -z "${all_cores[$1]-}" ]
then
echo >&2 "$SCRIPT_NAME: unrecognized core '$1'"
echo >&2 "Try '$SCRIPT_NAME --help' for usage."
exit 64 # EX_USAGE
else
cores+=( $1 )
shift
fi
done
fi
# Check that required Docker Compose services are up
service_containers="$($DOCKER_COMPOSE_CMD ps search 2>/dev/null)"
if ! echo "$service_containers" | grep -qw 'running\|Up'
then
echo >&2 "$SCRIPT_NAME: cannot delete indexed documents: " \
"the Docker Compose service 'search' is not up"
echo >&2 "Try '$DOCKER_COMPOSE_CMD up -d search' from '$MB_DOCKER_ROOT'"
exit 69 # EX_UNAVAILABLE
fi
# For each collection/core, delete all indexed documents
for core in "${cores[@]}"
do
echo -n "Posting deletion query for '$core'... "
$DOCKER_COMPOSE_CMD exec search post -c "${core/$'\r'/}" \
-d '<delete><query>*:*</query></delete>' >/dev/null
echo "Done"
done
if [ "${1:-shift}" = 'all' ]
then
echo "Successfully posted deletion queries for all collections."
fi
# vi: set et sts=2 sw=2 ts=2 :