Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alternate backend Solr implementations - WIP #345

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions includes/admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,74 @@ function islandora_solr_admin_index_settings($form, &$form_state) {
$form_state['values']['islandora_solr_url'] :
variable_get('islandora_solr_url', 'localhost:8080/solr');

// Solr connect triggering handler is dismax or not set on page load.
if ((isset($form_state['triggering_element']) &&
(($form_state['triggering_element']['#name'] == 'islandora_solr_url') ||
($form_state['triggering_element']['#name'] == 'islandora_solr_request_handler'))) ||
!isset($form_state['triggering_element'])) {
$form_state['triggering_element']['#name'] == 'islandora_solr_query_backends')
|| !isset($form_state['triggering_element'])) {

$query_backend = !empty($form_state['values']['islandora_solr_query_backend']) ?
$form_state['values']['islandora_solr_query_backend'] :
variable_get('islandora_solr_query_backend', ISLANDORA_SOLR_LEGACY_QUERY_BACKEND);

$backends = module_invoke_all(ISLANDORA_SOLR_QUERY_BACKEND_HOOK);
// Remove empty backends.
$backends = array_filter($backends, 'islandora_solr_filter_query_backends');
if (!isset($backends[$query_backend])) {
// If the hook no longer exists, switch to the legacy backend.
$query_backend = ISLANDORA_SOLR_LEGACY_QUERY_BACKEND;
}

// Check for the PHP Solr lib class.
if (!class_exists('Apache_Solr_Service')) {
$message = t('This module requires the <a href="!url">Apache Solr PHP Client</a>. Please install the client in the root directory of this module before continuing.', array('!url' => 'http://code.google.com/p/solr-php-client'));
drupal_set_message(check_plain($message));
return;
$backend_options = array();
foreach ($backends as $key => $backend) {
$backend_options[$key] = $backend['title'];
}

// Get request handler.
$handler = !empty($form_state['values']['islandora_solr_request_handler']) ? $form_state['values']['islandora_solr_request_handler'] : variable_get('islandora_solr_request_handler', FALSE);
$current_backend = $backends[$query_backend];

if (strpos($solr_url, 'https://') !== FALSE && strpos($solr_url, 'https://') == 0) {
if (!class_exists(islandora_solr_get_namespaced_class($current_backend, 'queryClass'))) {
$confirmation_message = format_string('<img src="@image_url"/>!message', array(
'@image_url' => file_create_url('misc/watchdog-error.png'),
'!message' => t('Islandora does not support SSL connections to Solr.'),
'!message' => t('Query class @class could not be loaded.',
array('@class' => ($current_backend['queryClass']))
),
));
$solr_avail = FALSE;
}
elseif (preg_match('/^([^\/]+):/', $solr_url) === 0) {

$form['islandora_solr_query_backends'] = array(
'#type' => 'select',
'#theme_wrappers' => array('container'),
'#attributes' => array(
'id' => 'solr_backend_wrapper',
),
'#title' => t('Solr backend implementations'),
'#description' => t('Selected implementation for querying Solr.'),
'#options' => $backend_options,
'#default_value' => $query_backend,
);
}

// Solr connect triggering handler is dismax or not set on page load.
if ((isset($form_state['triggering_element']) &&
(($form_state['triggering_element']['#name'] == 'islandora_solr_url') ||
($form_state['triggering_element']['#name'] == 'islandora_solr_request_handler'))) ||
!isset($form_state['triggering_element'])) {

// Get request handler.
$handler = !empty($form_state['values']['islandora_solr_request_handler']) ? $form_state['values']['islandora_solr_request_handler'] : variable_get('islandora_solr_request_handler', FALSE);

if (preg_match('/^([^\/]+):/', $solr_url) === 0) {
form_set_error('islandora_solr_url', t('Port number required in Solr URL.'));
$solr_avail = FALSE;
}
else {
// Check if Solr is available.
$solr_avail = islandora_solr_ping($solr_url);
try {
// Check if Solr is available.
$solr_avail = islandora_solr_ping($solr_url);
}
catch (Exception $e) {
$confirmation_message = $e->getMessage();
$solr_avail = FALSE;
}

$dismax_allowed = FALSE;
// If solr is available, get the request handlers.
Expand All @@ -71,7 +109,7 @@ function islandora_solr_admin_index_settings($form, &$form_state) {
)),
));
}
else {
elseif (!isset($confirmation_message)) {
$confirmation_message = format_string('<img src="@image_url"/>!message', array(
'@image_url' => file_create_url('misc/watchdog-error.png'),
'!message' => t('Unable to connect to Solr server at !link.', array(
Expand Down
18 changes: 9 additions & 9 deletions includes/luke.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ function islandora_solr_ping($solr_url) {
if (!isset($solr_url_parsed['host']) || !isset($solr_url_parsed['port'])) {
return FALSE;
}
// Call Solr.
$solr_service = new Apache_Solr_Service($solr_url_parsed['host'], $solr_url_parsed['port'], $solr_url_parsed['path'] . '/');
// Ping Solr.
$ping = $solr_service->ping();
// If a ping time is returned.
if ($ping) {
// Add 0.1 ms to the ping time so we never return 0.0.
return $ping + 0.01;

$backend = islandora_solr_get_current_backend();
$query_class = islandora_solr_get_namespaced_class($backend, 'queryClass');
if (!class_exists($query_class)) {
return FALSE;
}
return FALSE;

$solr_service = new $query_class();
// Ping Solr.
return $solr_service->ping($solr_url);
}

/**
Expand Down
Loading