function tripal_features_reindex
1.x indexFeatures.inc | tripal_features_reindex($max_sync, $job_id = NULL) |
Related topics
1 call to tripal_features_reindex()
- indexFeatures.inc in tripal_feature/
includes/ indexFeatures.inc - @todo Add file header description
1 string reference to 'tripal_features_reindex'
- tripal_feature_admin_validate in tripal_feature/
includes/ tripal_feature.admin.inc
File
- tripal_feature/
includes/ indexFeatures.inc, line 61 - @todo Add file header description
Code
function tripal_features_reindex($max_sync, $job_id = NULL) {
$i = 0;
// We register a shutdown function to ensure that the nodes
// that are indexed will have proper entries in the search_totals
// table. Without these entries, the searching doesn't work
// properly. This function may run for quite a while since
// it must calculate the sum of the scores of all entries in
// the search_index table. In the case of common words like
// 'contig', this will take quite a while
register_shutdown_function('search_update_totals');
// use this SQL statement to get the features that we're going to index. This
// SQL statement is derived from the hook_search function in the Drupal API.
// Essentially, this is the SQL statement that finds all nodes that need
// reindexing, but adjusted to include the chado_feature
$sql = "SELECT N.nid, N.title, CF.feature_id " .
"FROM {node} N " .
" INNER JOIN {chado_feature} CF ON CF.nid = N.nid ";
$results = db_query($sql);
// load into ids array
$count = 0;
$chado_features = array();
while ($chado_feature = db_fetch_object($results)) {
$chado_features[$count] = $chado_feature;
$count++;
}
// Iterate through features that need to be indexed
$interval = intval($count * 0.01);
if ($interval >= 0) {
$interval = 1;
}
foreach ($chado_features as $chado_feature) {
// update the job status every 1% features
if ($job_id and $i % $interval == 0) {
$prog = intval(($i / $count) * 100);
tripal_job_set_progress($job_id, $prog);
print "$prog%\n";
}
// sync only the max requested
if ($max_sync and $i == $max_sync) {
return '';
}
$i++;
/**
* tripal_feature_index_feature ($chado_feature->feature_id,$chado_feature->nid);
* parsing all the features can cause memory overruns
* we are not sure why PHP does not clean up the memory as it goes
* to avoid this problem we will call this script through an
* independent system call
*/
$cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/indexFeatures.php ";
$cmd .= "-i $chado_feature->feature_id -n $chado_feature->nid ";
# print "\t$cmd\n";
# print "\tfeature id is $chado_feature->feature_id\n";
# print "\tnid is $chado_feature->nid\n";
# print "\n";
system($cmd);
}
return '';
}