Skip to content

Instantly share code, notes, and snippets.

@mxr576
Last active March 6, 2017 10:31
Show Gist options
  • Save mxr576/c44d8b4bc9e3976a850ce04a0efd1ed0 to your computer and use it in GitHub Desktop.
Save mxr576/c44d8b4bc9e3976a850ce04a0efd1ed0 to your computer and use it in GitHub Desktop.
Drupal: Search API : Provide default Search API server which configuration can be overridden with variables
<?php
/**
* Implements hook_default_search_api_server().
*/
function MY_MODULE_default_search_api_server() {
$items = [];
$host = variable_get('solr_search_api_host', 'localhost');
$scheme = variable_get('solr_search_api_scheme', 'http');
$port = variable_get('solr_search_api_port', '8983');
$path = variable_get('solr_search_api_path', '\\/solr\\/drupal');
// Determine Solr version automatically.
$version = variable_get('solr_search_api_solr_version', NULL);
$class = variable_get('solr_search_api_solr_class', 'search_api_solr_service');
$excerpt = variable_get('solr_search_api_solr_excerpt', TRUE);
$retrieve_data = variable_get('solr_search_api_solr_retrieve_data', TRUE);
$highligh_data = variable_get('solr_search_api_solr_highlight_data', TRUE);
$items['master_solr_server'] = entity_import('search_api_server', '{
"name" : "Master Solr server",
"machine_name" : "master_solr_server",
"description" : "",
"class" : "' . $class . '",
"options" : {
"clean_ids" : true,
"site_hash" : true,
"scheme" : "' . $scheme . '",
"host" : "' . $host . '",
"port" : "' . $port . '",
"path" : "' . $path . '",
"http_user" : "",
"http_pass" : "",
"excerpt" : "' . $excerpt . '",
"retrieve_data" : "' . $retrieve_data . '",
"highlight_data" : "' . $highligh_data . '",
"skip_schema_check" : 0,
"solr_version" : "' . $version . '",
"http_method" : "AUTO"
},
"enabled" : "1"
}');
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment