Example #1
0
 public function __construct($path = SEARCH_INDEX_PATH)
 {
     global $CFG, $db;
     $this->path = $path;
     //test to see if there is a valid index on disk, at the specified path
     try {
         $test_index = new Zend_Search_Lucene($this->path, false);
         $validindex = true;
     } catch (Exception $e) {
         $validindex = false;
     }
     //catch
     //retrieve file system info about the index if it is valid
     if ($validindex) {
         $this->size = display_size(get_directory_size($this->path));
         $index_dir = get_directory_list($this->path, '', false, false);
         $this->filecount = count($index_dir);
         $this->indexcount = $test_index->count();
     } else {
         $this->size = 0;
         $this->filecount = 0;
         $this->indexcount = 0;
     }
     $db_exists = false;
     //for now
     //get all the current tables in moodle
     $admin_tables = $db->MetaTables();
     //TODO: use new IndexDBControl class for database checks?
     //check if our search table exists
     if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) {
         //retrieve database information if it does
         $db_exists = true;
         //total documents
         $this->dbcount = count_records(SEARCH_DATABASE_TABLE);
         //individual document types
         $types = search_get_document_types();
         sort($types);
         foreach ($types as $type) {
             $c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
             $this->types[$type] = (int) $c;
         }
     } else {
         $this->dbcount = 0;
         $this->types = array();
     }
     //check if the busy flag is set
     if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
         $this->complete = false;
     } else {
         $this->complete = true;
     }
     //get the last run date for the indexer
     if ($this->valid() && $CFG->search_indexer_run_date) {
         $this->time = $CFG->search_indexer_run_date;
     } else {
         $this->time = 0;
     }
 }
Example #2
0
         $chars = " \t\n\r\v,-+";
         // retrieve advanced query variables
         $adv->mustappear = trim(optional_param('mustappear', '', PARAM_CLEAN), $chars);
         $adv->notappear = trim(optional_param('notappear', '', PARAM_CLEAN), $chars);
         $adv->canappear = trim(optional_param('canappear', '', PARAM_CLEAN), $chars);
         $adv->module = optional_param('module', '', PARAM_CLEAN);
         $adv->title = trim(optional_param('title', '', PARAM_CLEAN), $chars);
         $adv->author = trim(optional_param('author', '', PARAM_CLEAN), $chars);
     }
 }
 if ($advanced) {
     //parse the advanced variables into a query string
     //TODO: move out to external query class (QueryParse?)
     $query_string = '';
     // get all available module types
     $module_types = array_merge(array('all'), array_values(search_get_document_types()));
     $adv->module = in_array($adv->module, $module_types) ? $adv->module : 'all';
     // convert '1 2' into '+1 +2' for required words field
     if (strlen(trim($adv->mustappear)) > 0) {
         $query_string = ' +' . implode(' +', preg_split("/[\\s,;]+/", $adv->mustappear));
     }
     // convert '1 2' into '-1 -2' for not wanted words field
     if (strlen(trim($adv->notappear)) > 0) {
         $query_string .= ' -' . implode(' -', preg_split("/[\\s,;]+/", $adv->notappear));
     }
     // this field is left untouched, apart from whitespace being stripped
     if (strlen(trim($adv->canappear)) > 0) {
         $query_string .= ' ' . implode(' ', preg_split("/[\\s,;]+/", $adv->canappear));
     }
     // add module restriction
     $doctypestr = get_string('doctype', 'search');
Example #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;
}
Example #4
0
    $chars = " \t\n\r\v,-+";
    // retrieve advanced query variables
    $adv->mustappear = trim(optional_param('mustappear', '', PARAM_CLEAN), $chars);
    $adv->notappear = trim(optional_param('notappear', '', PARAM_CLEAN), $chars);
    $adv->canappear = trim(optional_param('canappear', '', PARAM_CLEAN), $chars);
    $adv->module = optional_param('module', '', PARAM_CLEAN);
    $adv->title = trim(optional_param('title', '', PARAM_CLEAN), $chars);
    $adv->author = trim(optional_param('author', '', PARAM_CLEAN), $chars);
}
if ($advanced) {
    //parse the advanced variables into a query string
    //TODO: move out to external query class (QueryParse?)
    $query_string = '';
    // get all available module types adding third party modules
    $module_types = array_merge(array('all'), array_values(search_get_document_types()));
    $module_types = array_merge($module_types, array_values(search_get_document_types('X_SEARCH_TYPE')));
    $adv->module = in_array($adv->module, $module_types) ? $adv->module : 'all';
    // convert '1 2' into '+1 +2' for required words field
    if (strlen(trim($adv->mustappear)) > 0) {
        $query_string = ' +' . implode(' +', preg_split("/[\\s,;]+/", $adv->mustappear));
    }
    // convert '1 2' into '-1 -2' for not wanted words field
    if (strlen(trim($adv->notappear)) > 0) {
        $query_string .= ' -' . implode(' -', preg_split("/[\\s,;]+/", $adv->notappear));
    }
    // this field is left untouched, apart from whitespace being stripped
    if (strlen(trim($adv->canappear)) > 0) {
        $query_string .= ' ' . implode(' ', preg_split("/[\\s,;]+/", $adv->canappear));
    }
    // add module restriction
    $doctypestr = 'doctype';
Example #5
0
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
    print_error('onlyadmins', 'error', get_login_url());
}
mtrace('<pre>Server Time: ' . date('r', time()));
mtrace("Testing global search capabilities:\n");
//fix paths for testing
set_include_path(get_include_path() . ":../");
require_once "{$CFG->dirroot}/search/Zend/Search/Lucene.php";
mtrace("Checking activity modules:\n");
//the presence of the required search functions -
// * mod_iterator
// * mod_get_content_for_index
//are the sole basis for including a module in the index at the moment.
/// 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) {
        if (in_array($mod->name, $searchabletypes)) {
            $mod->location = 'internal';
            $searchables[] = $mod;
        } else {
            $documentfile = $CFG->dirroot . "/mod/{$mod->name}/search_document.php";
            $mod->location = 'mod';
            if (file_exists($documentfile)) {
                $searchables[] = $mod;
            }
        }
    }
    mtrace(count($searchables) . ' modules to search in / ' . count($mods) . ' modules found.');
}
/// collects blocks as indexable information may be found in blocks either