-
Notifications
You must be signed in to change notification settings - Fork 0
/
solr_schema_initializer.sh
258 lines (230 loc) · 9.14 KB
/
solr_schema_initializer.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env bash
#
# This script updates ontology schema with ngram based new search fields. These new text fields has naming: *_autosuggest_e,
# *_autosuggest_se, *_autosuggest_ne and *_autosuggest_ts, and enable partial matching capability. To run this script,
# your solr should be up and running and the latest dump file, solr.json, is uploaded.
#
# Important: After the schema change, reindexing is required. For this purpose, you can simply re-upload the dump data
# to the ontology collection.
#
# Usage:
# bash solr_post_config.sh -h localhost -p 8993
set -e
autocomplete_single_val_fields=(label)
autocomplete_multi_val_fields=(synonym_hasExactSynonym synonym_hasNarrowSynonym synonym_hasBroadSynonym)
autocomplete_fields=("${autocomplete_single_val_fields[@]}" "${autocomplete_multi_val_fields[@]}")
while getopts h:p:c: flag
do
case "${flag}" in
h) host=${OPTARG};;
p) port=${OPTARG};;
c) collection=${OPTARG};;
*) echo "!!! Invalid flag. Only -h and -p flags are supported."
esac
done
echo "Updating $collection in server $host:$port"
echo "Adding texEdge field type"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field-type\":{
\"name\":\"textEdge\",
\"class\":\"solr.TextField\",
\"indexAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.StandardTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.WordDelimiterGraphFilterFactory\",
\"splitOnCaseChange\":\"0\"},
{\"class\":\"solr.LowerCaseFilterFactory\"},
{\"class\":\"solr.EdgeNGramFilterFactory\",
\"minGramSize\":\"2\",
\"maxGramSize\":\"35\"}]
},
\"queryAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.WhitespaceTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.WordDelimiterGraphFilterFactory\",
\"splitOnCaseChange\":\"0\"},
{\"class\":\"solr.EnglishMinimalStemFilterFactory\"},
{\"class\":\"solr.LowerCaseFilterFactory\"}]
}
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding textShingleEdge field type"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field-type\":{
\"name\":\"textShingleEdge\",
\"class\":\"solr.TextField\",
\"indexAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.StandardTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.ShingleFilterFactory\",
\"maxShingleSize\":\"4\",
\"outputUnigrams\":\"false\"},
{\"class\":\"solr.LowerCaseFilterFactory\" },
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\"}]
},
\"queryAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.KeywordTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.LowerCaseFilterFactory\" },
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\"}]
}
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding nameExact field type"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field-type\":{
\"name\":\"nameExact\",
\"class\":\"solr.TextField\",
\"indexAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.KeywordTokenizerFactory\"},
\"filters\":[{\"class\":\"solr.LowerCaseFilterFactory\" },
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\"}]
},
\"queryAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.KeywordTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.LowerCaseFilterFactory\"},
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\" }]
}
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding textStart field type"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field-type\":{
\"name\":\"textStart\",
\"class\":\"solr.TextField\",
\"indexAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.KeywordTokenizerFactory\"},
\"filters\":[{\"class\":\"solr.LowerCaseFilterFactory\" },
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\"},
{\"class\":\"solr.EdgeNGramFilterFactory\",
\"minGramSize\":\"3\",
\"maxGramSize\":\"35\"}]
},
\"queryAnalyzer\":{
\"tokenizer\":{
\"class\":\"solr.KeywordTokenizerFactory\" },
\"filters\":[{\"class\":\"solr.LowerCaseFilterFactory\"},
{\"class\":\"solr.RemoveDuplicatesTokenFilterFactory\"}]
}
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete single value fields: ${autocomplete_single_val_fields[*]}"
for field in "${autocomplete_single_val_fields[@]}"; do
echo "Adding auto complete field e: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_e\",
\"type\":\"textEdge\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":false
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field se: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_se\",
\"type\":\"textShingleEdge\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":false
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field ne: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_ne\",
\"type\":\"nameExact\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":false
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field ts: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_ts\",
\"type\":\"textStart\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":false,
\"omitNorms\":false
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
done
echo "Adding auto complete multi value fields: ${autocomplete_multi_val_fields[*]}"
for field in "${autocomplete_multi_val_fields[@]}"; do
echo "Adding auto complete field e: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_e\",
\"type\":\"textEdge\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":true
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field se: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_se\",
\"type\":\"textShingleEdge\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":true
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field ne: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_ne\",
\"type\":\"nameExact\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":true
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Adding auto complete field ts: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-field\":{
\"name\":\"${field}_autosuggest_ts\",
\"type\":\"textStart\",
\"indexed\":true,
\"stored\":true,
\"multiValued\":true,
\"omitNorms\":false
}
}" http://$host:$port/solr/$collection/schema --show-error --fail
done
echo "Copying auto complete fields: ${autocomplete_fields[*]}"
for field in "${autocomplete_fields[@]}"; do
echo "Copying auto complete field e: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-copy-field\":{
\"source\":\"${field}\",
\"dest\":\"${field}_autosuggest_e\"}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Copying auto complete field se: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-copy-field\":{
\"source\":\"${field}\",
\"dest\":\"${field}_autosuggest_se\"}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Copying auto complete field ne: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-copy-field\":{
\"source\":\"${field}\",
\"dest\":\"${field}_autosuggest_ne\"}
}" http://$host:$port/solr/$collection/schema --show-error --fail
echo "Copying auto complete field ts: ${field}"
curl -X POST -H 'Content-type:application/json' --data-binary "{
\"add-copy-field\":{
\"source\":\"${field}\",
\"dest\":\"${field}_autosuggest_ts\"}
}" http://$host:$port/solr/$collection/schema --show-error --fail
done
echo "successfully finished configuring solr schema with the Schema API."
echo "SUCCESS"