
So, say MuhmadEmad you have built a great custom search solution for Drupal on top of Solr using Search API. You don’t want to lose it, so you export the entire config using Features, right? No-brainer…
Oh, wait – the client wants to host on Acquia and wholesale NFL jerseys use their Solr service. Sure, there’s a module for that as well.
But… How do you properly adapt your exported settings to work on Acquia without having to create a whole duplicate server and wholesale MLB jerseys index config? Enter the Drupal hook system! Search API provides an alter hook for server definitions that allows you to intercept the server configs before they are processed into the Search API C?P subsystem. Here’s a sample cheap NFL jerseys of how Hacked you can keep your existing settings and simply alter them to point to the correct Solr instance when running on Acquia:
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
|
/**
* Implements hook_default_search_api_server_alter
* We’re using this to flip the default search server to Acquia’s instances based on their hosting env vars
*/
function MODULE_default_search_api_server_alter(array &$defaults) {
global $_ENV;
// If we have the Solr server definition already set AND we’re in the Acquia Cloud, swap out server definitions
if (isset($defaults[‘my_solr_server’]) && isset($_ENV[‘AH_SITE_ENVIRONMENT’])) {
$defaults[‘my_solr_server’] = entity_import(‘search_api_server’, ‘{
“name” : “My Solr Server [Acquia]”,
“machine_name” : “my_solr_server”,
“description” : “”,
“class” : “acquia_search_service”,
“options” : {
“scheme” : “http”,
“host” : “useast1-c1.acquia-search.com”,
“port” : “80”,
“path” : “\\/solr\\/’ . variable_get(‘acquia_identifier’, ”) . ‘”,
“edismax” : 0,
“modify_acquia_connection” : 0,
“http_user” : “”,
“http_pass” : “”,
“excerpt” : 0,
“retrieve_data” : 1,
“highlight_data” : 0,
“http_method” : “POST”
},
“enabled” : “1”,
“rdf_mapping” : []
}’);
}
}
|
The alter hook replaces the stock Search API Solr settings with the Acquia Search API server settings, examining the AH_SITE_ENVIRONMENT to determine if rebooted! we’re on an Acquia server and taking advantage of the subscription variable that all Acquia subscription sites have for the subscription key. No muss, no fuss! Clear caches and/or revert your search Feature, and away you go!