Esempio n. 1
0
}
*/
try {
    $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
} catch (LuceneException $e) {
    mtrace("Could not construct a valid index. Maybe the first indexation was never made, or files might be corrupted. Run complete indexation again.");
    return;
}
$dbcontrol = new IndexDBControl();
$update_count = 0;
$indexdate = 0 + @$CFG->search_indexer_update_date;
$startupdatedate = time();
/// indexing changed resources
mtrace("Starting index update (updates)...\n");
if ($mods = get_records_select('modules')) {
    $mods = array_merge($mods, search_get_additional_modules());
    foreach ($mods as $mod) {
        $class_file = $CFG->dirroot . '/search/documents/' . $mod->name . '_document.php';
        $get_document_function = $mod->name . '_single_document';
        $delete_function = $mod->name . '_delete';
        $db_names_function = $mod->name . '_db_names';
        $updates = array();
        if (file_exists($class_file)) {
            require_once $class_file;
            //if both required functions exist
            if (function_exists($delete_function) and function_exists($db_names_function) and function_exists($get_document_function)) {
                mtrace("Checking {$mod->name} module for updates.");
                $valuesArray = $db_names_function();
                if ($valuesArray) {
                    foreach ($valuesArray as $values) {
                        $where = !empty($values[5]) ? 'AND (' . $values[5] . ')' : '';
Esempio n. 2
0
        if (in_array('SEARCH_TYPE_' . strtoupper($block->name), $searchabletypes)) {
            $mod->location = 'internal';
            $blocks_searchables[] = $block;
        } else {
            $documentfile = $CFG->dirroot . "/blocks/{$block->dirname}/search_document.php";
            if (file_exists($documentfile)) {
                $mod->location = 'blocks';
                $blocks_searchables[] = $block;
            }
        }
    }
    mtrace(count($blocks_searchables) . ' blocks to search in / ' . count($blocks) . ' blocks found.');
    $searchables = array_merge($searchables, $blocks_searchables);
}
/// add virtual modules onto the back of the array
$additional = search_get_additional_modules();
mtrace(count($additional) . ' additional to search in.');
$searchables = array_merge($searchables, $additional);
foreach ($searchables as $mod) {
    $key = 'search_in_' . $mod->name;
    if (isset($CFG->{$key}) && !$CFG->{$key}) {
        mtrace("module {$key} has been administratively disabled. Skipping...\n");
        continue;
    }
    if ($mod->location == 'internal') {
        $class_file = $CFG->dirroot . '/search/documents/' . $mod->name . '_document.php';
    } else {
        $class_file = $CFG->dirroot . '/' . $mod->location . '/' . $mod->name . '/search_document.php';
    }
    if (file_exists($class_file)) {
        include_once $class_file;
Esempio n. 3
0
/**
* collects all searchable items identities
* @param boolean $namelist if true, only returns list of names of searchable items
* @param boolean $verbose if true, prints a discovering status
* @return an array of names or an array of type descriptors
*/
function search_collect_searchables($namelist = false, $verbose = true)
{
    global $CFG, $DB;
    $searchables = array();
    $searchables_names = array();
    /// get all installed modules
    if ($mods = $DB->get_records('modules', null, 'name', 'id,name')) {
        $searchabletypes = array_values(search_get_document_types());
        foreach ($mods as $mod) {
            $plugin = new StdClass();
            $plugin->name = $mod->name;
            $plugin->type = 'mod';
            if (in_array($mod->name, $searchabletypes)) {
                $plugin->location = 'internal';
                $searchables[$plugin->name] = $plugin;
                $searchables_names[] = $mod->name;
            } else {
                $documentfile = $CFG->dirroot . "/mod/{$mod->name}/search_document.php";
                $plugin->location = 'mod';
                if (file_exists($documentfile)) {
                    $searchables[$plugin->name] = $plugin;
                    $searchables_names[] = $mod->name;
                }
            }
        }
        if ($verbose) {
            mtrace(count($searchables) . ' modules to search in / ' . count($mods) . ' modules found.');
        }
    }
    /// collects blocks as indexable information may be found in blocks either
    if ($blocks = $DB->get_records('block', null, 'name', 'id,name')) {
        $blocks_searchables = array();
        // prepend the "block_" prefix to discriminate document type plugins
        foreach ($blocks as $block) {
            $plugin = new StdClass();
            $plugin->dirname = $block->name;
            $plugin->name = 'block_' . $block->name;
            if (in_array('SEARCH_TYPE_' . strtoupper($block->name), $searchabletypes)) {
                $plugin->location = 'internal';
                $plugin->type = 'block';
                $blocks_searchables[$plugin->name] = $plugin;
                $searchables_names[] = $plugin->name;
            } else {
                $documentfile = $CFG->dirroot . "/blocks/{$plugin->dirname}/search_document.php";
                if (file_exists($documentfile)) {
                    $plugin->location = 'blocks';
                    $plugin->type = 'block';
                    $blocks_searchables[$plugin->name] = $plugin;
                    $searchables_names[] = $plugin->name;
                }
            }
        }
        if ($verbose) {
            mtrace(count($blocks_searchables) . ' blocks to search in / ' . count($blocks) . ' blocks found.');
        }
        $searchables = array_merge($searchables, $blocks_searchables);
    }
    /// add virtual modules onto the back of the array
    $additional = search_get_additional_modules($searchables_names);
    if (!empty($additional)) {
        if ($verbose) {
            mtrace(count($additional) . ' additional to search in.');
        }
        $searchables = array_merge($searchables, $additional);
    }
    if ($namelist) {
        return $searchables_names;
    }
    return $searchables;
}
Esempio n. 4
0
// collects modules
if ($mods = get_records('modules', '', '', '', 'id,name')) {
    $searchables = array_merge($searchables, $mods);
}
mtrace(count($searchables) . ' modules found.');
// collects blocks as indexable information may be found in blocks either
if ($blocks = get_records('block', '', '', '', 'id,name')) {
    // prepend the "block_" prefix to discriminate document type plugins
    foreach (array_keys($blocks) as $aBlockId) {
        $blocks[$aBlockId]->name = 'block_' . $blocks[$aBlockId]->name;
    }
    $searchables = array_merge($searchables, $blocks);
    mtrace(count($blocks) . ' blocks found.');
}
//add virtual modules onto the back of the array
$searchables = array_merge($searchables, search_get_additional_modules());
if ($searchables) {
    foreach ($searchables as $mod) {
        $class_file = $CFG->dirroot . '/search/documents/' . $mod->name . '_document.php';
        if (file_exists($class_file)) {
            include_once $class_file;
            //build function names
            $iter_function = $mod->name . '_iterator';
            $index_function = $mod->name . '_get_content_for_index';
            $counter = 0;
            if (function_exists($index_function) && function_exists($iter_function)) {
                mtrace("Processing module function {$index_function} ...");
                $sources = $iter_function();
                if ($sources) {
                    foreach ($sources as $i) {
                        $documents = $index_function($i);