mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-53325 search: Optimize Solr less often
This commit is contained in:
parent
7adc7ef14f
commit
bf2235bb11
@ -1028,7 +1028,8 @@ $string['taskdeleteincompleteusers'] = 'Delete incomplete users';
|
||||
$string['taskdeleteunconfirmedusers'] = 'Delete unconfirmed users';
|
||||
$string['taskeventscron'] = 'Background processing for events';
|
||||
$string['taskfiletrashcleanup'] = 'Cleanup files in trash';
|
||||
$string['taskglobalsearch'] = 'Global search indexing';
|
||||
$string['taskglobalsearchindex'] = 'Global search indexing';
|
||||
$string['taskglobalsearchoptimize'] = 'Global search index optimization';
|
||||
$string['taskgradecron'] = 'Background processing for gradebook';
|
||||
$string['tasklegacycron'] = 'Legacy cron processing for plugins';
|
||||
$string['taskmessagingcleanup'] = 'Background processing for messaging';
|
||||
|
@ -30,7 +30,7 @@ namespace core\task;
|
||||
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class search_task extends scheduled_task {
|
||||
class search_index_task extends scheduled_task {
|
||||
|
||||
/**
|
||||
* Get a descriptive name for this task (shown to admins).
|
||||
@ -38,7 +38,7 @@ class search_task extends scheduled_task {
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return get_string('taskglobalsearch', 'admin');
|
||||
return get_string('taskglobalsearchindex', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,8 +53,5 @@ class search_task extends scheduled_task {
|
||||
|
||||
// Indexing database records for modules + rich documents of forum.
|
||||
$globalsearch->index();
|
||||
|
||||
// Optimize index at last.
|
||||
$globalsearch->optimize_index();
|
||||
}
|
||||
}
|
61
lib/classes/task/search_optimize_task.php
Normal file
61
lib/classes/task/search_optimize_task.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* A scheduled task for global search.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2016 Eric Merrill {@link https://www.merrilldigital.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Runs search index optimization.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2016 Eric Merrill {@link https://www.merrilldigital.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class search_optimize_task extends scheduled_task {
|
||||
|
||||
/**
|
||||
* Get a descriptive name for this task (shown to admins).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return get_string('taskglobalsearchoptimize', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
@ -285,7 +285,7 @@ $tasks = array(
|
||||
'month' => '*'
|
||||
),
|
||||
array(
|
||||
'classname' => 'core\task\search_task',
|
||||
'classname' => 'core\task\search_index_task',
|
||||
'blocking' => 0,
|
||||
'minute' => '*/30',
|
||||
'hour' => '*',
|
||||
@ -293,6 +293,15 @@ $tasks = array(
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
),
|
||||
array(
|
||||
'classname' => 'core\task\search_optimize_task',
|
||||
'blocking' => 0,
|
||||
'minute' => '15',
|
||||
'hour' => '*/12',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
),
|
||||
array(
|
||||
'classname' => 'core\task\stats_cron_task',
|
||||
'blocking' => 0,
|
||||
|
@ -229,6 +229,19 @@ abstract class engine {
|
||||
return $classname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run any post indexing operations.
|
||||
*
|
||||
* Should be overwritten if the search engine needs to do any post index cleanup.
|
||||
*
|
||||
* @param int $numdocs The number of documents that were added to the index
|
||||
* @param bool $fullindex True if a full index was performed
|
||||
* @return void
|
||||
*/
|
||||
public function index_complete($numdocs = 0, $fullindex = false) {
|
||||
// Nothing by default.
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimizes the search engine.
|
||||
*
|
||||
|
@ -474,7 +474,7 @@ class manager {
|
||||
// Unlimited time.
|
||||
\core_php_time_limit::raise();
|
||||
|
||||
$anyupdate = false;
|
||||
$sumdocs = 0;
|
||||
|
||||
$searchareas = $this->get_search_areas_list(true);
|
||||
foreach ($searchareas as $areaid => $searcharea) {
|
||||
@ -527,7 +527,7 @@ class manager {
|
||||
}
|
||||
|
||||
if ($numdocs > 0) {
|
||||
$anyupdate = true;
|
||||
$sumdocs += $numdocs;
|
||||
|
||||
// Commit all remaining documents.
|
||||
$this->engine->commit();
|
||||
@ -551,13 +551,15 @@ class manager {
|
||||
}
|
||||
}
|
||||
|
||||
if ($anyupdate) {
|
||||
if ($sumdocs > 0) {
|
||||
$event = \core\event\search_indexed::create(
|
||||
array('context' => \context_system::instance()));
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
return $anyupdate;
|
||||
$this->engine->index_complete($sumdocs, $fullindex);
|
||||
|
||||
return (bool)$sumdocs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ $string['extensionerror'] = 'The Apache Solr PHP extension is not installed. Ple
|
||||
$string['missingconfig'] = 'Your Apache Solr server is not yet configured in Moodle.';
|
||||
$string['multivaluedfield'] = 'Field "{$a}" returned an array instead of a scalar, the field is probably defined in Solr with "Multivalued" to true, this means that Solr autocreated the field for you when you indexed data because you forgot to run search/engine/solr/cli/setup_schema.php. Please delete the current index, create a new one and run setup_schema.php before indexing data in Solr.';
|
||||
$string['nodatafromserver'] = 'No data from server';
|
||||
$string['optimizetask'] = 'Optimize Solr index';
|
||||
$string['pluginname'] = 'Solr';
|
||||
$string['schemafieldautocreated'] = 'Field "{$a}" already exists in Solr schema. You probably forgot to run this script before indexing data and fields were autocreated by Solr. Please delete the current index, create a new one and run setup_schema.php again before indexing data in Solr.';
|
||||
$string['searchinfo'] = 'Search queries';
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2016030400.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2016030400.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user