You are here

function _as_index_documents in Apache Solr Attachments 5

Take the full list of Docs to submit to Solr and add them in batches.

1 call to _as_index_documents()
apachesolr_attachments_update_index in ./apachesolr_attachments.module
Hook is called by search.module to add things to the search index. In our case we will search content types and add any CCK type that is a file type that we know how to parse and any uploaded file attachments.

File

./apachesolr_attachments.module, line 368
Provides a file attachment search implementation for use with the Apache Solr module

Code

function _as_index_documents($documents) {
  $solr = _asa_get_solr_instance();
  if (is_object($solr) && count($documents) > 0) {
    watchdog(SOLR_ATTACHMENT_WD, t("Adding @count documents to Solr", array(
      '@count' => count($documents),
    )));
    try {

      // Chunk the adds by 50s
      $docs_chunk = array_chunk($documents, 50);
      foreach ($docs_chunk as $docs) {
        $solr
          ->addDocuments($docs);
      }
      $solr
        ->commit();
      $solr
        ->optimize(FALSE, FALSE);
    } catch (Exception $e) {
      watchdog(SOLR_ATTACHMENT_WD, $e
        ->getMessage(), WATCHDOG_ERROR);
    }
  }
}