You are here

function apachesolr_nan_process_solr_indexes in Apache Solr Not-A-Node 7

Same name and namespace in other branches
  1. 7.2 apachesolr_nan.module \apachesolr_nan_process_solr_indexes()

Send information to solr for indexing.

Parameters

string $path: A string representing the path to index.

string $title: A string representing the title as it should appear in the search index.

string $description: A string representing additional search terms or a description that will be helpful for users to find the page.

int $fnid: An interger that will be used to designate the node id of the non-node. The "f" stands for fake. This should be a negative number to keep it out of the normal node id space. If a positive integer is received it will be multiplied by negative one.

1 call to apachesolr_nan_process_solr_indexes()
apachesolr_nan_cron in ./apachesolr_nan.module
Implements hook_cron().

File

./apachesolr_nan.module, line 56
Provides hook and common functions for non-node searching.

Code

function apachesolr_nan_process_solr_indexes($path, $title, $description, $fnid) {
  if ($fnid > 0 && is_numeric($fnid)) {
    $fnid = (int) $fnid * -1;
  }
  global $user;
  drupal_save_session(FALSE);
  $saved_user = $user;

  // 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
  $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;
  $env_id = variable_get('apachesolr_nan_nan_env', apachesolr_default_environment());
  $entity_type = 'node';
  $bundle = 'basic_page';
  $bundle_name = 'Basic Page';
  $item = menu_get_item(drupal_get_normal_path($path));
  if (empty($item['access'])) {
    apachesolr_index_delete_entity_from_index($env_id, 'node', $fnid);
    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']);
  $content = render($content);
  $document = new ApacheSolrDocument();
  $document->id = apachesolr_document_id($fnid, $entity_type);
  $document->site = $base_url;
  $document->hash = apachesolr_site_hash();
  $document->entity_id = $fnid;
  $document->entity_type = $entity_type;
  $document->bundle = $bundle;
  $document->bundle_name = $bundle_name;
  $document->ss_language = LANGUAGE_NONE;
  $document->path = $path;
  $document->url = url($path);
  $document->path_alias = $path;
  $document->label = $title;
  $document->content = apachesolr_clean_text($description . ' ' . $content);
  $document->teaser = truncate_utf8($document->content, 300, TRUE);
  $documents[] = $document;
  apachesolr_index_send_to_solr($env_id, $documents);

  // Restore the user.
  $user = $saved_user;
  drupal_save_session(TRUE);
}