function apachesolr_attachments_update_index in Apache Solr Attachments 5
Same name and namespace in other branches
- 6 apachesolr_attachments.module \apachesolr_attachments_update_index()
- 6.2 apachesolr_attachments.module \apachesolr_attachments_update_index()
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 98 - Provides a file attachment search implementation for use with the Apache Solr module
Code
function apachesolr_attachments_update_index() {
$result = ApacheSolrUpdate::getNodesToIndex(SOLR_ATTACHMENT_NS);
while ($row = db_fetch_object($result)) {
// Variables to track the last item changed.
$solr_last_change = $row->last_change;
$solr_last_id = $row->nid;
$node = node_load($row->nid);
if ($node->nid) {
// Since there is no notification for an attachment being unassociated with a
// node (but that action will trigger it to be indexed again), lets remove
// all indexed attachments then add all attached (if any)
_asa_remove_attachments_from_index($node->nid);
$files = _asa_get_indexable_files($node);
if (!empty($files)) {
// Update solr index.
try {
foreach ($files as $file) {
// Some are arrays others are objects, treat them all as objects
$file = (object) $file;
$text = _asa_get_attachment_text($file);
$text = trim($text);
if (!empty($text)) {
$document = new Apache_Solr_Document();
$site = url(NULL, NULL, NULL, TRUE);
$hash = md5($site);
$document->site = $site;
$document->hash = $hash;
$document->url = file_create_url($file->filepath);
$document->id = $file->fid;
$document->nid = $node->nid;
$document->title = $file->filename;
$document->changed = $node->changed;
$document->uid = $node->uid;
$document->body = $text;
$document->text = "{$file->description} {$file->filename} {$text}";
$document->type = $node->type;
$document->bsfield_isfile = TRUE;
_as_configure_taxonomy($document, $node);
// Let modules add to the document
foreach (module_implements('apachesolr_attachments_update_index') as $module) {
$function = $module . '_apachesolr_attachments_update_index';
$function($document, $node, $file);
}
$documents[] = $document;
}
}
} catch (Exception $e) {
watchdog(SOLR_ATTACHMENT_WD, $e
->getMessage(), WATCHDOG_ERROR);
}
}
ApacheSolrUpdate::success(SOLR_ATTACHMENT_NS, $solr_last_change, $solr_last_id);
}
}
_as_index_documents($documents);
}