diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc
index f84d503..76d2c44 100644
--- a/apachesolr.admin.inc
+++ b/apachesolr.admin.inc
@@ -537,11 +537,13 @@ function apachesolr_settings(array $form, array &$form_state) {
* Gets information about the fields already in solr index.
*
* @param array $environment
- * The environment for which we need to ask the status from
+ * The environment for which we need to ask the status from.
*
- * @return array page render array
+ * @return array
+ * Page render array.
*/
function apachesolr_status_page($environment = array()) {
+ $output = array();
if (empty($environment)) {
$env_id = apachesolr_default_environment();
$environment = apachesolr_environment_load($env_id);
@@ -550,10 +552,10 @@ function apachesolr_status_page($environment = array()) {
$env_id = $environment['env_id'];
}
- // Check for availability
+ // Check for availability.
if (!apachesolr_server_status($environment['url'], $environment['service_class'])) {
- drupal_set_message(t('The server seems to be unavailable. Please verify the server settings at the settings page', array('!settings_page' => url("admin/config/search/apachesolr/settings/{$environment['env_id']}/edit", array('query' => drupal_get_destination())))), 'warning');
- return '';
+ drupal_set_message(t('The server seems to be unavailable. Please verify the server settings at the settings page', array('!settings_page' => url("admin/config/search/apachesolr/settings/{$environment['env_id']}/edit", array('query' => drupal_get_destination())))), 'warning');
+ return $output;
}
try {
@@ -564,14 +566,14 @@ function apachesolr_status_page($environment = array()) {
catch (Exception $e) {
watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
drupal_set_message(nl2br(check_plain($e->getMessage())), "warning");
- $data = new stdClass;
+ $data = new stdClass();
$data->fields = array();
}
$messages = array();
if (isset($data->index->numDocs)) {
try {
- // Collect the stats
+ // Collect the stats.
$stats_summary = $solr->getStatsSummary();
module_load_include('inc', 'apachesolr', 'apachesolr.index');
$status = apachesolr_index_status($environment["env_id"]);
@@ -593,18 +595,32 @@ function apachesolr_status_page($environment = array()) {
$messages[] = array(t('Indexed'), $indexed_message);
$remaining_message = t('@items (@percentage% has been sent to the server)', array(
- '@items' => format_plural($status['remaining'], t('1 item'), t('@count items')),
- '@percentage' => ((int)min(100, 100 * ($status['total'] - $status['remaining']) / max(1, $status['total']))),
- )
- );
+ '@items' => format_plural($status['remaining'], t('1 item'), t('@count items')),
+ '@percentage' => ((int) min(100, 100 * ($status['total'] - $status['remaining']) / max(1, $status['total']))),
+ ));
$messages[] = array(t('Remaining'), $remaining_message);
$messages[] = array(t('Schema'), t('@schema_version', $stats_summary));
if (!empty($stats_summary['@core_name'])) {
- $messages[] = array(t('Solr Core Name'), t('@core_name', $stats_summary));
+ $messages[] = array(
+ t('Solr Core Name'),
+ t('@core_name', $stats_summary),
+ );
}
- $messages[] = array(t('Delay'), t('@autocommit_time before updates are processed.', $stats_summary));
- $messages[] = array(t('Pending Deletions'), t('@deletes_total', $stats_summary));
+
+ $direct_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_direct_commit', FALSE);
+ if ($direct_commit) {
+ $delay_msg = t('Updates are processed immediately');
+ }
+ else {
+ $delay_msg = t('@autocommit_time before updates are processed', $stats_summary);
+ }
+ $messages[] = array(t('Delay'), $delay_msg);
+
+ $messages[] = array(
+ t('Pending Deletions'),
+ t('@deletes_total', $stats_summary),
+ );
}
catch (Exception $e) {
watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
@@ -628,11 +644,11 @@ function apachesolr_status_page($environment = array()) {
$write_status = apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE);
if ($write_status == APACHESOLR_READ_WRITE) {
- $output['index_action_form'] = drupal_get_form('apachesolr_index_action_form', $env_id);
- $output['index_config_form'] = drupal_get_form('apachesolr_index_config_form', $env_id);
+ $output['index_action_form'] = drupal_get_form('apachesolr_index_action_form', $env_id);
+ $output['index_config_form'] = drupal_get_form('apachesolr_index_config_form', $env_id);
}
else {
- drupal_set_message(t('Options for deleting and re-indexing are not available because the index is read-only. This can be changed on the settings page', array('!settings_page' => url('admin/config/search/apachesolr/settings/' . $env_id . '/edit', array('query' => drupal_get_destination())))), 'warning');
+ drupal_set_message(t('Options for deleting and re-indexing are not available because the index is read-only. This can be changed on the settings page', array('!settings_page' => url('admin/config/search/apachesolr/settings/' . $env_id . '/edit', array('query' => drupal_get_destination())))), 'warning');
}
return $output;
diff --git a/apachesolr.index.inc b/apachesolr.index.inc
index 94588ef..5bd2e35 100644
--- a/apachesolr.index.inc
+++ b/apachesolr.index.inc
@@ -331,18 +331,22 @@ function apachesolr_convert_entity_to_documents($entity, $entity_type, $env_id)
/**
* Index an array of documents to solr.
*
- * @param $env_id
+ * @param string $env_id
+ * Environment ID.
* @param array $documents
+ * Set of documents.
+ *
+ * @return bool|int
+ * Number indexed, or FALSE on failure.
*
- * @return bool|int number indexed, or FALSE on failure.
* @throws Exception
*/
function apachesolr_index_send_to_solr($env_id, array $documents) {
- // Get the $solr object
+ // Get the $solr object.
$solr = apachesolr_get_solr($env_id);
// Do not index when we do not have any documents to send
- // Send TRUE because this is not an error
+ // Send TRUE because this is not an error.
if (empty($documents)) {
return TRUE;
}
@@ -361,6 +365,11 @@ function apachesolr_index_send_to_solr($env_id, array $documents) {
'@count' => count($documents),
), WATCHDOG_INFO);
}
+ // Directly process those documents if direct commit was enabled.
+ $direct_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_direct_commit', FALSE);
+ if ($direct_commit) {
+ $solr->commit();
+ }
return count($documents);
}
catch (Exception $e) {
@@ -696,9 +705,12 @@ function apachesolr_index_delete_bundles($env_id, $entity_type, array $excluded_
* @param string $env_id
* The machine name of the environment.
* @param string $entity_type
+ * Entity type.
* @param string $entity_id
+ * Entity ID.
*
- * @return true on success, false on failure.
+ * @return bool
+ * TRUE on success.
*/
function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entity_id) {
static $failed = FALSE;
@@ -720,6 +732,11 @@ function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entit
watchdog('Apache Solr', 'Deleted documents from index with query @query', array('@query' => $query), WATCHDOG_INFO);
}
apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
+ // Directly process those documents if direct commit was enabled.
+ $direct_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_direct_commit', FALSE);
+ if ($direct_commit) {
+ $solr->commit();
+ }
return TRUE;
}
catch (Exception $e) {
@@ -1477,6 +1494,11 @@ function apachesolr_index_nodeapi_mass_update(array $nodes, $table = NULL) {
$solr = apachesolr_get_solr($env_id);
$solr->deleteByMultipleIds($unpublished_ids);
apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
+ // Directly process those documents if direct commit was enabled.
+ $direct_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_direct_commit', FALSE);
+ if ($direct_commit) {
+ $solr->commit();
+ }
// There was no exception, so update the table.
if ($published_ids) {
@@ -1531,6 +1553,11 @@ function apachesolr_index_nodeapi_mass_delete(array $nodes, $table = NULL) {
$solr = apachesolr_get_solr($env_id);
$solr->deleteByMultipleIds($ids);
apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
+ // Directly process those documents if direct commit was enabled.
+ $direct_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_direct_commit', FALSE);
+ if ($direct_commit) {
+ $solr->commit();
+ }
// There was no exception, so update the table.
db_delete($table)
->condition('entity_id', $nids, 'IN')