-
Notifications
You must be signed in to change notification settings - Fork 301
/
execute_all.php
230 lines (202 loc) · 8.88 KB
/
execute_all.php
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
<?php
use Solarium\Core\Client\Request;
use Solarium\Exception\HttpException;
use Solarium\Support\Utility;
try {
require(__DIR__.'/init.php');
$collection_or_core_name = $config['endpoint']['localhost']['core'] = uniqid();
// only necessary for solrcloud mode, but needs to be set to retrieve the mode from admin/info/system
$config['endpoint']['localhost']['username'] = 'solr';
$config['endpoint']['localhost']['password'] = 'SolrRocks';
// create a client instance
$client = new Solarium\Client($adapter, $eventDispatcher, $config);
$query = $client->createApi([
'handler' => 'admin/info/system',
'version' => Request::API_V1,
]);
$data = $client->execute($query)->getData();
$solr_mode = $data['mode'] ?? 'server';
$solrSpecVersion = $data['lucene']['solr-spec-version'];
$solrVersion = (int) strstr($solrSpecVersion, '.', true);
if ('solrcloud' === $data['mode']) {
$config['endpoint']['localhost']['collection'] = $config['endpoint']['localhost']['core'];
unset($config['endpoint']['localhost']['core']);
// adjust the client instance
$client = new Solarium\Client($adapter, $eventDispatcher, $config);
// upload the techproducts configset
$configsetsQuery = $client->createConfigsets();
$UploadAction = $configsetsQuery->createUpload();
$UploadAction
->setFile(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Integration'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'techproducts.zip')
->setName('techproducts')
->setOverwrite(true);
$configsetsQuery->setAction($UploadAction);
$client->configsets($configsetsQuery);
// create core with unique name using the techproducts configset
$collectionsQuery = $client->createCollections();
$createAction = $collectionsQuery->createCreate();
$createAction->setName($collection_or_core_name)
->setCollectionConfigName('techproducts')
->setNumShards(2);
$collectionsQuery->setAction($createAction);
$client->collections($collectionsQuery);
} else {
$coreAdminQuery = $client->createCoreAdmin();
// create core with unique name using the techproducts configset
$createAction = $coreAdminQuery->createCreate();
$createAction->setCore($collection_or_core_name)
->setConfigSet('sample_techproducts_configs');
$coreAdminQuery->setAction($createAction);
$response = $client->coreAdmin($coreAdminQuery);
}
// @todo Figure out why this fails on Solr 9.
if (9 !== $solrVersion) {
// check if /mlt handler exists (it will in the github worklow, but not when running this script on its own)
$query = $client->createApi([
'version' => Request::API_V1,
'handler' => $collection_or_core_name.'/config/requestHandler',
]);
$query->addParam('componentName', '/mlt');
$response = $client->execute($query);
$mltHandler = $response->getData()['config']['requestHandler']['/mlt'];
if (null === $mltHandler) {
// set up /mlt handler for MoreLikeThis query examples
$query = $client->createApi([
'version' => Request::API_V1,
'handler' => $collection_or_core_name.'/config',
'method' => Request::METHOD_POST,
'rawdata' => json_encode([
'add-requesthandler' => [
'name' => '/mlt',
'class' => 'solr.MoreLikeThisHandler',
],
]),
]);
$client->execute($query);
}
}
// check if attr_* dynamic field definition exists (it was removed from the techproducts configset in Solr 9.1)
try {
$query = $client->createApi([
'version' => Request::API_V1,
'handler' => $collection_or_core_name.'/schema/dynamicfields/'.rawurlencode('attr_*'),
]);
$response = $client->execute($query);
} catch (HttpException $e) {
$query = $client->createApi([
'version' => Request::API_V1,
'handler' => $collection_or_core_name.'/schema',
'method' => Request::METHOD_POST,
'rawdata' => json_encode([
'add-dynamic-field' => [
'name' => 'attr_*',
'type' => 'text_general',
'indexed' => true,
'stored' => true,
'multiValued' => true,
],
]),
]);
$client->execute($query);
}
// disable automatic commits for update examples
$query = $client->createApi([
'version' => Request::API_V1,
'handler' => $collection_or_core_name.'/config',
'method' => Request::METHOD_POST,
'rawdata' => json_encode([
'set-property' => [
'updateHandler.autoCommit.maxDocs' => -1,
'updateHandler.autoCommit.maxTime' => -1,
'updateHandler.autoCommit.openSearcher' => true,
'updateHandler.autoSoftCommit.maxDocs' => -1,
'updateHandler.autoSoftCommit.maxTime' => -1,
],
]),
]);
$client->execute($query);
// index techproducts sample data
$dataDir = __DIR__.
DIRECTORY_SEPARATOR.'..'.
DIRECTORY_SEPARATOR.'lucene-solr'.
DIRECTORY_SEPARATOR.'solr'.
DIRECTORY_SEPARATOR.'example'.
DIRECTORY_SEPARATOR.'exampledocs';
foreach (glob($dataDir.DIRECTORY_SEPARATOR.'*.xml') as $file) {
$update = $client->createUpdate();
$update->setRequestFormat($update::REQUEST_FORMAT_XML);
if (null !== $encoding = Utility::getXmlEncoding($file)) {
$update->setInputEncoding($encoding);
}
$update->addRawXmlFile($file);
$client->update($update);
}
$update = $client->createUpdate();
$update->addCommit(true, true);
$client->update($update);
// examples that can't be run against techproducts
$skipAltogether = [
'2.1.5.8-distributed-search.php',
'7.5.3-plugin-bufferedupdate-benchmarks.php', // intended to be included, not to be run standalone
'7.5.3.1-plugin-bufferedupdate-benchmarks-xml.php', // takes too long for a workflow, can be run manually
'7.5.3.2-plugin-bufferedupdate-lite-benchmarks-xml.php', // takes too long for a workflow, can be run manually
'7.5.3.3-plugin-bufferedupdate-benchmarks-json.php', // takes too long for a workflow, can be run manually
'7.5.3.4-plugin-bufferedupdate-lite-benchmarks-json.php', // takes too long for a workflow, can be run manually
];
// examples that can't be run against this Solr version
$skipForVersion = [];
if (9 === $solrVersion) {
$skipForVersion[] = '2.3.1-mlt-query.php';
$skipForVersion[] = '2.3.2-mlt-stream.php';
}
// examples that can't be run in cloud mode
$skipForCloud = [
'2.1.5.7-grouping-by-query.php',
'2.2.5-rollback.php',
'2.10.2-managedresources-stopwords.php',
'2.10.3-managedresources-synonyms.php',
'7.1-plugin-loadbalancer.php',
];
foreach (scandir(__DIR__) as $example) {
if (preg_match('/^\d.*\.php/', $example)) {
print "\n".$example.' ';
if (in_array($example, $skipAltogether)) {
print 'Could not be run against the techproducts example.';
} elseif (in_array($example, $skipForVersion)) {
printf('Could not be run against Solr %d.', $solrVersion);
} elseif ('solrcloud' === $solr_mode && in_array($example, $skipForCloud)) {
print 'Could not be run in cloud mode.';
} else {
ob_start();
require($example);
ob_end_clean();
}
}
}
if ('solrcloud' === $solr_mode) {
$collectionsQuery = $client->createCollections();
$deleteAction = $collectionsQuery->createDelete();
$deleteAction->setName($collection_or_core_name);
$collectionsQuery->setAction($deleteAction);
$client->collections($collectionsQuery);
$configsetsQuery = $client->createConfigsets();
$action = $configsetsQuery->createDelete();
$action->setName('techproducts');
$configsetsQuery->setAction($action);
$client->configsets($configsetsQuery);
} else {
$coreAdminQuery = $client->createCoreAdmin();
$unloadAction = $coreAdminQuery->createUnload();
$unloadAction->setCore($collection_or_core_name)
->setDeleteDataDir(true)
->setDeleteIndex(true)
->setDeleteInstanceDir(true);
$coreAdminQuery->setAction($unloadAction);
$client->coreAdmin($coreAdminQuery);
}
} catch (\Exception $e) {
print $e;
exit(1);
}
print "\n\n";
exit(0);