Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 121... Línea 121...
121
     * @var string Core search area category for results that do not fit into any of existing categories.
121
     * @var string Core search area category for results that do not fit into any of existing categories.
122
     */
122
     */
123
    const SEARCH_AREA_CATEGORY_OTHER = 'core-other';
123
    const SEARCH_AREA_CATEGORY_OTHER = 'core-other';
Línea 124... Línea 124...
124
 
124
 
-
 
125
    /**
-
 
126
     * @var int To avoid race conditions, do not index documents newer than this many seconds.
-
 
127
     */
-
 
128
    const INDEXING_DELAY = 5;
-
 
129
 
125
    /**
130
    /**
126
     * @var \core_search\base[] Enabled search areas.
131
     * @var \core_search\base[] Enabled search areas.
127
     */
132
     */
Línea 128... Línea 133...
128
    protected static $enabledsearchareas = null;
133
    protected static $enabledsearchareas = null;
Línea 1191... Línea 1196...
1191
     * @param float $timelimit Time limit in seconds (0 = no time limit)
1196
     * @param float $timelimit Time limit in seconds (0 = no time limit)
1192
     * @param \progress_trace|null $progress Optional class for tracking progress
1197
     * @param \progress_trace|null $progress Optional class for tracking progress
1193
     * @throws \moodle_exception
1198
     * @throws \moodle_exception
1194
     * @return bool Whether there was any updated document or not.
1199
     * @return bool Whether there was any updated document or not.
1195
     */
1200
     */
1196
    public function index($fullindex = false, $timelimit = 0, \progress_trace $progress = null) {
1201
    public function index($fullindex = false, $timelimit = 0, ?\progress_trace $progress = null) {
1197
        global $DB;
1202
        global $DB, $CFG;
Línea 1198... Línea 1203...
1198
 
1203
 
1199
        // Cannot combine time limit with reindex.
1204
        // Cannot combine time limit with reindex.
1200
        if ($timelimit && $fullindex) {
1205
        if ($timelimit && $fullindex) {
1201
            throw new \coding_exception('Cannot apply time limit when reindexing');
1206
            throw new \coding_exception('Cannot apply time limit when reindexing');
Línea 1227... Línea 1232...
1227
 
1232
 
1228
            // Decide time to stop.
1233
            // Decide time to stop.
1229
            $stopat = self::get_current_time() + $timelimit;
1234
            $stopat = self::get_current_time() + $timelimit;
Línea -... Línea 1235...
-
 
1235
        }
-
 
1236
 
-
 
1237
        // Work out if we are in test mode, in which case we disable the indexing delay (because
-
 
1238
        // the normal pattern is to add a document and immediately index it).
-
 
1239
        $testmode = (PHPUNIT_TEST || defined('BEHAT_TEST')) &&
1230
        }
1240
            empty($CFG->searchindexingdelayfortestscript);
Línea 1231... Línea 1241...
1231
 
1241
 
Línea 1232... Línea 1242...
1232
        foreach ($searchareas as $areaid => $searcharea) {
1242
        foreach ($searchareas as $areaid => $searcharea) {
Línea 1242... Línea 1252...
1242
            // This is used to store this component config.
1252
            // This is used to store this component config.
1243
            list($componentconfigname, $varname) = $searcharea->get_config_var_name();
1253
            list($componentconfigname, $varname) = $searcharea->get_config_var_name();
Línea 1244... Línea 1254...
1244
 
1254
 
Línea -... Línea 1255...
-
 
1255
            $prevtimestart = intval(get_config($componentconfigname, $varname . '_indexingstart'));
-
 
1256
 
-
 
1257
            // The effective start time of previous indexing was some seconds earlier because we
-
 
1258
            // only index data up to that time, to avoid race conditions (if it takes a while to
-
 
1259
            // write a document to the database and the timecreated for that document ends up being
-
 
1260
            // a second or two out of date). This mechanism is disabled for tests.
-
 
1261
            if (!$testmode) {
-
 
1262
                // The -1 here is because for example, if _indexingstart is 123, we will have
-
 
1263
                // indexed everything up to 123 - 5 = 118 (inclusive). So next time, we can start
-
 
1264
                // at 119 = 123 - 4 and we don't have to repeat 118.
-
 
1265
                $prevtimestart -= (self::INDEXING_DELAY - 1);
1245
            $prevtimestart = intval(get_config($componentconfigname, $varname . '_indexingstart'));
1266
            }
1246
 
1267
 
Línea 1247... Línea 1268...
1247
            if ($fullindex === true) {
1268
            if ($fullindex === true) {
1248
                $referencestarttime = 0;
1269
                $referencestarttime = 0;
Línea 1276... Línea 1297...
1276
            $options = array('indexfiles' => $fileindexing, 'lastindexedtime' => $prevtimestart);
1297
            $options = array('indexfiles' => $fileindexing, 'lastindexedtime' => $prevtimestart);
1277
            if ($timelimit) {
1298
            if ($timelimit) {
1278
                $options['stopat'] = $stopat;
1299
                $options['stopat'] = $stopat;
1279
            }
1300
            }
1280
            $options['progress'] = $progress;
1301
            $options['progress'] = $progress;
-
 
1302
            // Skip 'future' documents, also any written very recently (to avoid race conditions).
-
 
1303
            // The exception is for PHPunit and Behat (step 'I update the global search index')
-
 
1304
            // where we allow it to index recent documents as well, we don't want it to have to wait.
1281
            $iterator = new skip_future_documents_iterator(new \core\dml\recordset_walk(
1305
            $iterator = new skip_future_documents_iterator(
1282
                    $recordset, array($searcharea, 'get_document'), $options));
1306
                new \core\dml\recordset_walk($recordset, [$searcharea, 'get_document'], $options),
-
 
1307
                $indexingstart - ($testmode ? 0 : self::INDEXING_DELAY),
-
 
1308
            );
1283
            $result = $this->engine->add_documents($iterator, $searcharea, $options);
1309
            $result = $this->engine->add_documents($iterator, $searcharea, $options);
1284
            $recordset->close();
1310
            $recordset->close();
1285
            $batchinfo = '';
1311
            $batchinfo = '';
1286
            if (count($result) === 6) {
1312
            if (count($result) === 6) {
1287
                [$numrecords, $numdocs, $numdocsignored, $lastindexeddoc, $partial, $batches] = $result;
1313
                [$numrecords, $numdocs, $numdocsignored, $lastindexeddoc, $partial, $batches] = $result;
Línea 1363... Línea 1389...
1363
     * @param string $startfromarea Area to start from
1389
     * @param string $startfromarea Area to start from
1364
     * @param int $startfromtime Timestamp to start from
1390
     * @param int $startfromtime Timestamp to start from
1365
     * @return \stdClass Object indicating success
1391
     * @return \stdClass Object indicating success
1366
     */
1392
     */
1367
    public function index_context($context, $singleareaid = '', $timelimit = 0,
1393
    public function index_context($context, $singleareaid = '', $timelimit = 0,
1368
            \progress_trace $progress = null, $startfromarea = '', $startfromtime = 0) {
1394
            ?\progress_trace $progress = null, $startfromarea = '', $startfromtime = 0) {
1369
        if (!$progress) {
1395
        if (!$progress) {
1370
            $progress = new \null_progress_trace();
1396
            $progress = new \null_progress_trace();
1371
        }
1397
        }
Línea 1372... Línea 1398...
1372
 
1398
 
Línea 1687... Línea 1713...
1687
     * If there are no index requests, the function will do nothing.
1713
     * If there are no index requests, the function will do nothing.
1688
     *
1714
     *
1689
     * @param float $timelimit Time limit (0 = none)
1715
     * @param float $timelimit Time limit (0 = none)
1690
     * @param \progress_trace|null $progress Optional progress indicator
1716
     * @param \progress_trace|null $progress Optional progress indicator
1691
     */
1717
     */
1692
    public function process_index_requests($timelimit = 0.0, \progress_trace $progress = null) {
1718
    public function process_index_requests($timelimit = 0.0, ?\progress_trace $progress = null) {
1693
        global $DB;
1719
        global $DB;
Línea 1694... Línea 1720...
1694
 
1720
 
1695
        if (!$progress) {
1721
        if (!$progress) {
1696
            $progress = new \null_progress_trace();
1722
            $progress = new \null_progress_trace();