Example #1
0
 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     if (!\core_search\manager::is_global_search_enabled()) {
         return;
     }
     $globalsearch = \core_search\manager::instance();
     // Optimize index at last.
     $globalsearch->optimize_index();
 }
Example #2
0
 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     if (!\core_search\manager::is_global_search_enabled()) {
         return;
     }
     $globalsearch = \core_search\manager::instance();
     // Indexing database records for modules + rich documents of forum.
     $globalsearch->index();
 }
Example #3
0
 public function test_search_enabled()
 {
     $this->resetAfterTest();
     // Disabled by default.
     $this->assertFalse(\core_search\manager::is_global_search_enabled());
     set_config('enableglobalsearch', true);
     $this->assertTrue(\core_search\manager::is_global_search_enabled());
     set_config('enableglobalsearch', false);
     $this->assertFalse(\core_search\manager::is_global_search_enabled());
 }
Example #4
0
/**
 * Global search report
 *
 * @package   report_search
 * @copyright Prateek Sachan {@link http://prateeksachan.com}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../config.php';
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('reportsearch');
$pagetitle = get_string('pluginname', 'report_search');
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
if (\core_search\manager::is_global_search_enabled() === false) {
    $renderer = $PAGE->get_renderer('core_search');
    echo $renderer->render_search_disabled();
    echo $OUTPUT->footer();
    exit;
}
$renderer = $PAGE->get_renderer('report_search');
$search = \core_search\manager::instance();
// All enabled components.
$searchareas = $search->get_search_areas_list(true);
$mform = new \report_search\output\form(null, array('searchareas' => $searchareas));
if ($data = $mform->get_data()) {
    if (!empty($data->delete)) {
        if (!empty($data->all)) {
            $search->delete_index();
        } else {
Example #5
0
 */
define('CLI_SCRIPT', true);
require __DIR__ . '/../../config.php';
require_once $CFG->libdir . '/clilib.php';
// cli only functions
list($options, $unrecognized) = cli_get_params(array('help' => false, 'force' => false, 'reindex' => false), array('h' => 'help', 'f' => 'force', 'r' => 'reindex'));
if ($unrecognized) {
    $unrecognized = implode("\n  ", $unrecognized);
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
if ($options['help']) {
    $help = "Index search data\n\nOptions:\n-h, --help            Print out this help\n-r, --reindex         Reindex data\n-f, --force           Allow indexer to run, even if global search is disabled.\n\nExample:\n\$ sudo -u www-data /usr/bin/php search/cli/indexer.php --reindex\n";
    echo $help;
    die;
}
if (!\core_search\manager::is_global_search_enabled() && empty($options['force'])) {
    cli_error('Global search is disabled. Use --force if you want to force an index while disabled');
}
if (!($searchengine = \core_search\manager::search_engine_instance())) {
    cli_error(get_string('engineserverstatus', 'search'));
}
if (!$searchengine->is_installed()) {
    cli_error('enginenotinstalled', 'search', $CFG->searchengine);
}
$serverstatus = $searchengine->is_server_ready();
if ($serverstatus !== true) {
    cli_error($serverstatus);
}
$globalsearch = \core_search\manager::instance();
if (empty($options['reindex'])) {
    echo "Running full index of site\n";
Example #6
0
 /**
  * Builds the HTML to display the control
  *
  * @param string $data Unused
  * @param string $query
  * @return string
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT;
     $return = '';
     $brtag = html_writer::empty_tag('br');
     // Available search areas.
     $searchareas = \core_search\manager::get_search_areas_list();
     $anyenabled = false;
     $anyindexed = false;
     foreach ($searchareas as $areaid => $searcharea) {
         list($componentname, $varname) = $searcharea->get_config_var_name();
         if (!$anyenabled) {
             $anyenabled = get_config($componentname, $varname . '_enabled');
         }
         if (!$anyindexed) {
             $anyindexed = get_config($componentname, $varname . '_indexingstart');
         }
         if ($anyenabled && $anyindexed) {
             break;
         }
     }
     $return .= $OUTPUT->heading(get_string('searchsetupinfo', 'admin'), 3, 'main');
     $table = new html_table();
     $table->head = array(get_string('step', 'search'), get_string('status'));
     $table->colclasses = array('leftalign step', 'leftalign status');
     $table->id = 'searchsetup';
     $table->attributes['class'] = 'admintable generaltable';
     $table->data = array();
     $return .= $brtag . get_string('searchsetupdescription', 'search') . $brtag . $brtag;
     // Select a search engine.
     $row = array();
     $url = new moodle_url('/admin/settings.php?section=manageglobalsearch#admin-searchengine');
     $row[0] = '1. ' . html_writer::tag('a', get_string('selectsearchengine', 'admin'), array('href' => $url));
     $status = html_writer::tag('span', get_string('no'), array('class' => 'statuscritical'));
     if (!empty($CFG->searchengine)) {
         $status = html_writer::tag('span', get_string('pluginname', 'search_' . $CFG->searchengine), array('class' => 'statusok'));
     }
     $row[1] = $status;
     $table->data[] = $row;
     // Available areas.
     $row = array();
     $url = new moodle_url('/admin/settings.php?section=manageglobalsearch#admin-searchengine');
     $row[0] = '2. ' . html_writer::tag('a', get_string('enablesearchareas', 'admin'), array('href' => $url));
     $status = html_writer::tag('span', get_string('no'), array('class' => 'statuscritical'));
     if ($anyenabled) {
         $status = html_writer::tag('span', get_string('yes'), array('class' => 'statusok'));
     }
     $row[1] = $status;
     $table->data[] = $row;
     // Setup search engine.
     $row = array();
     if (empty($CFG->searchengine)) {
         $row[0] = '3. ' . get_string('setupsearchengine', 'admin');
         $row[1] = html_writer::tag('span', get_string('no'), array('class' => 'statuscritical'));
     } else {
         $url = new moodle_url('/admin/settings.php?section=search' . $CFG->searchengine);
         $row[0] = '3. ' . html_writer::tag('a', get_string('setupsearchengine', 'admin'), array('href' => $url));
         // Check the engine status.
         $searchengine = \core_search\manager::search_engine_instance();
         $serverstatus = $searchengine->is_server_ready();
         if ($serverstatus === true) {
             $status = html_writer::tag('span', get_string('yes'), array('class' => 'statusok'));
         } else {
             $status = html_writer::tag('span', $serverstatus, array('class' => 'statuscritical'));
         }
         $row[1] = $status;
     }
     $table->data[] = $row;
     // Indexed data.
     $row = array();
     $url = new moodle_url('/report/search/index.php#searchindexform');
     $row[0] = '4. ' . html_writer::tag('a', get_string('indexdata', 'admin'), array('href' => $url));
     if ($anyindexed) {
         $status = html_writer::tag('span', get_string('yes'), array('class' => 'statusok'));
     } else {
         $status = html_writer::tag('span', get_string('no'), array('class' => 'statuscritical'));
     }
     $row[1] = $status;
     $table->data[] = $row;
     // Enable global search.
     $row = array();
     $url = new moodle_url("/admin/search.php?query=enableglobalsearch");
     $row[0] = '5. ' . html_writer::tag('a', get_string('enableglobalsearch', 'admin'), array('href' => $url));
     $status = html_writer::tag('span', get_string('no'), array('class' => 'statuscritical'));
     if (\core_search\manager::is_global_search_enabled()) {
         $status = html_writer::tag('span', get_string('yes'), array('class' => 'statusok'));
     }
     $row[1] = $status;
     $table->data[] = $row;
     $return .= html_writer::table($table);
     return highlight($query, $return);
 }
Example #7
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Adds moodle fields to solr schema.
 *
 * Schema REST API write actions are only available from Solr 4.4 onwards.
 *
 * The schema should be managed and mutable to allow this script
 * to add new fields to the schema.
 *
 * @link      https://cwiki.apache.org/confluence/display/solr/Managed+Schema+Definition+in+SolrConfig
 * @package   search_solr
 * @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_login(null, false);
require_capability('moodle/site:config', context_system::instance());
if (!\core_search\manager::is_global_search_enabled()) {
    throw new moodle_exception('globalsearchdisabled', 'search');
}
if ($CFG->searchengine !== 'solr') {
    throw new moodle_exception('solrnotselected', 'search_solr');
}
$schema = new \search_solr\schema();
$schema->setup();
$url = new moodle_url('/admin/settings.php', array('section' => 'manageglobalsearch'));
redirect($url, get_string('setupok', 'search_solr'), 4);
Example #8
-1
 /**
  * Gets the block contents.
  *
  * If we can avoid it better not check the server status here as connecting
  * to the server will slow down the whole page load.
  *
  * @return string The block HTML.
  */
 public function get_content()
 {
     global $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (\core_search\manager::is_global_search_enabled() === false) {
         $this->content->text = get_string('globalsearchdisabled', 'search');
         return $this->content;
     }
     $url = new moodle_url('/search/index.php');
     $this->content->footer .= html_writer::link($url, get_string('advancedsearch', 'search'));
     $this->content->text = html_writer::start_tag('div', array('class' => 'searchform'));
     $this->content->text .= html_writer::start_tag('form', array('action' => $url->out()));
     $this->content->text .= html_writer::start_tag('fieldset', array('action' => 'invisiblefieldset'));
     // Input.
     $this->content->text .= html_writer::tag('label', get_string('search', 'search'), array('for' => 'searchform_search', 'class' => 'accesshide'));
     $inputoptions = array('id' => 'searchform_search', 'name' => 'q', 'type' => 'text', 'size' => '15');
     $this->content->text .= html_writer::empty_tag('input', $inputoptions);
     // Search button.
     $this->content->text .= html_writer::tag('button', get_string('search', 'search'), array('id' => 'searchform_button', 'type' => 'submit', 'title' => 'globalsearch'));
     $this->content->text .= html_writer::end_tag('fieldset');
     $this->content->text .= html_writer::end_tag('form');
     $this->content->text .= html_writer::end_tag('div');
     return $this->content;
 }