-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_api_federated_solr.drush.inc
82 lines (69 loc) · 2.34 KB
/
search_api_federated_solr.drush.inc
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
<?php
/**
* @file
* Drush commands for Search API Federated Solr.
*/
use Drupal\search_api\Entity\Server;
use Drupal\search_api\SearchApiException;
/**
* Implements hook_drush_command().
*/
function search_api_federated_solr_drush_command() {
$items = [];
$items['search-api-federated-solr-fields'] = [
'description' => 'List all fields, as they map to solr machine names, for the search api index used by the federated search app.',
'examples' => [
'drush sapifs-f' => dt('List all fields, as they map to solr machine names, for the search api index used by the federated search app.'),
],
'aliases' => ['sapifs-f'],
];
return $items;
}
/**
* List all fields, as they map to solr machine names, for the search api index used by the federated search app.
*/
function drush_search_api_federated_solr_fields() {
// Get index id from search app config.
$config = \Drupal::configFactory()->get('search_api_federated_solr.search_app.settings');
$index_id = $config->get('index.id');
if (!$index_id) {
drush_print('In order to return the solr field names, please choose a search api index in the federated search app settings.');
return;
}
// Get the server id from index config.
$index_config = Drupal::config('search_api.index.' . $index_id);
$server_id = $index_config->get('server');
// Load the server.
/** @var \Drupal\search_api\ServerInterface $server */
$server = Server::load($server_id);
try {
/** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
$backend = $server->getBackend();
}
catch (SearchApiException $e) {
drush_print('Could not connect to the Solr backend for the search api server.');
return;
}
// Load the index.
$indexes = $server->getIndexes();
/** @var \Drupal\search_api\IndexInterface $federated_search_index */
$federated_search_index = $indexes[$index_id];
// Get index field names mapped to their solr field name counterparts
$field_names = $backend->getSolrFieldNames($federated_search_index);
$rows[] = array(
dt('Index Field Machine Name'),
dt('| Solr Field Machine Name'),
);
$rows[] = array(
dt('-------------------------'),
dt('| -----------------------'),
);
foreach ($field_names as $key => $value) {
$row = array(
$key,
'| ' . $value,
);
$rows[] = $row;
}
drush_print_table($rows);
}