function apachesolr_nan_process_solr_indexes in Apache Solr Not-A-Node 7.2
Same name and namespace in other branches
- 7 apachesolr_nan.module \apachesolr_nan_process_solr_indexes()
function apachesolr_nan_process_solr_indexes().
Send information to solr for indexing.
Parameters
Object $nan: An object representing the apachesolr_nan entity (thing to be indexed).
1 call to apachesolr_nan_process_solr_indexes()
- apachesolr_nan_cron in ./
apachesolr_nan.module - Implements hook_cron().
File
- ./
apachesolr_nan.module, line 99 - Provides hook and common functions for non-node searching.
Code
function apachesolr_nan_process_solr_indexes($nan) {
// build the content for the index as an anonymous user to avoid exposing
// restricted fields and such. By setting a variable, indexing can take place
// as a different user
global $user;
drupal_save_session(FALSE);
$saved_user = $user;
$uid = variable_get('apachesolr_index_user', 0);
if ($uid == 0) {
$user = drupal_anonymous_user();
}
else {
$user = user_load($uid);
}
module_load_include('inc', 'apachesolr', 'apachesolr.index');
global $base_url;
global $language;
$env_id = variable_get('apachesolr_nan_nan_env', apachesolr_default_environment());
$entity_type = 'apachesolr_nan';
$item = menu_get_item($nan->path);
if (empty($item['access'])) {
apachesolr_index_delete_entity_from_index($env_id, 'nan', $nan->id);
watchdog('ApacheSolr NAN search', 'Access to %id from path %path is not allowed to be viewed by the indexing user and has been removed..', array(
'%id' => $fnid,
'%path' => $path,
));
return FALSE;
}
$function = $item['page_callback'];
if (!empty($item['include_file'])) {
require_once $item['include_file'];
}
$content = call_user_func_array($function, $item['page_arguments']);
if (is_array($content)) {
$content = $content['content'];
}
// Create the Solr document and send it to the index.
$document = new ApacheSolrDocument();
$document->id = apachesolr_document_id($nan->id, $entity_type);
$document->is_uid = $user->uid;
$document->site = $base_url;
$document->hash = apachesolr_site_hash();
$document->entity_id = $nan->id;
$document->entity_type = $entity_type;
$document->ss_language = $language->language;
$document->path = $nan->path;
$document->url = url($nan->path, array(
'absolute' => TRUE,
));
$document->path_alias = $nan->path;
$document->label = $nan->title;
$document->content = apachesolr_clean_text($content);
$document->teaser = truncate_utf8($document->content, 300, TRUE);
$document->sm_title_field = array(
$nan->title,
);
$documents[] = $document;
apachesolr_index_send_to_solr($env_id, $documents);
// Restore the user.
$user = $saved_user;
drupal_save_session(TRUE);
}