Skip to content

Commit

Permalink
Merge branch 'MDL-58654_global_search_batch' of https://github.com/ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed May 31, 2017
2 parents ea1676f + 0a9a10f commit 4ff1fef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
44 changes: 44 additions & 0 deletions search/classes/engine.php
Expand Up @@ -198,6 +198,50 @@ protected function to_document(\core_search\base $searcharea, $docdata) {
return $doc;
}

/**
* Loop through given iterator of search documents
* and and have the search engine back end add them
* to the index.
*
* @param iterator $iterator the iterator of documents to index
* @param searcharea $searcharea the area for the documents to index
* @param array $options document indexing options
* @return array Processed document counts
*/
public function add_documents($iterator, $searcharea, $options) {
$numrecords = 0;
$numdocs = 0;
$numdocsignored = 0;
$lastindexeddoc = 0;

foreach ($iterator as $document) {
if (!$document instanceof \core_search\document) {
continue;
}

if ($options['lastindexedtime'] == 0) {
// If we have never indexed this area before, it must be new.
$document->set_is_new(true);
}

if ($options['indexfiles']) {
// Attach files if we are indexing.
$searcharea->attach_files($document);
}

if ($this->add_document($document, $options['indexfiles'])) {
$numdocs++;
} else {
$numdocsignored++;
}

$lastindexeddoc = $document->get('modified');
$numrecords++;
}

return array($numrecords, $numdocs, $numdocsignored, $lastindexeddoc);
}

/**
* Returns the plugin name.
*
Expand Down
41 changes: 9 additions & 32 deletions search/classes/manager.php
Expand Up @@ -546,15 +546,11 @@ public function index($fullindex = false) {
$this->engine->area_index_starting($searcharea, $fullindex);

$indexingstart = time();
$elapsed = microtime(true);

// This is used to store this component config.
list($componentconfigname, $varname) = $searcharea->get_config_var_name();

$numrecords = 0;
$numdocs = 0;
$numdocsignored = 0;
$lastindexeddoc = 0;

$prevtimestart = intval(get_config($componentconfigname, $varname . '_indexingstart'));

if ($fullindex === true) {
Expand All @@ -570,36 +566,17 @@ public function index($fullindex = false) {
$fileindexing = $this->engine->file_indexing_enabled() && $searcharea->uses_file_indexing();
$options = array('indexfiles' => $fileindexing, 'lastindexedtime' => $prevtimestart);
$iterator = new \core\dml\recordset_walk($recordset, array($searcharea, 'get_document'), $options);
foreach ($iterator as $document) {
if (!$document instanceof \core_search\document) {
continue;
}

if ($prevtimestart == 0) {
// If we have never indexed this area before, it must be new.
$document->set_is_new(true);
}

if ($fileindexing) {
// Attach files if we are indexing.
$searcharea->attach_files($document);
}

if ($this->engine->add_document($document, $fileindexing)) {
$numdocs++;
} else {
$numdocsignored++;
}

$lastindexeddoc = $document->get('modified');
$numrecords++;
}
list($numrecords,
$numdocs,
$numdocsignored,
$lastindexeddoc) = $this->engine->add_documents($iterator, $searcharea, $options);

if (CLI_SCRIPT && !PHPUNIT_TEST) {
if ($numdocs > 0) {
$elapsed = round((microtime(true) - $elapsed), 3);
mtrace('Processed ' . $numrecords . ' records containing ' . $numdocs . ' documents for ' .
$searcharea->get_visible_name() . ' area.');
} else {
$searcharea->get_visible_name() . ' area, in ' . $elapsed . ' seconds.');
} else {
mtrace('No new documents to index for ' . $searcharea->get_visible_name() . ' area.');
}
}
Expand Down Expand Up @@ -698,7 +675,7 @@ public function get_areas_config($searchareas) {

$vars = array('indexingstart', 'indexingend', 'lastindexrun', 'docsignored', 'docsprocessed', 'recordsprocessed');

$configsettings = array();
$configsettings = [];
foreach ($searchareas as $searcharea) {

$areaid = $searcharea->get_area_id();
Expand Down

0 comments on commit 4ff1fef

Please sign in to comment.