diff --git a/search/engine/solr/classes/document.php b/search/engine/solr/classes/document.php index 34760f0b47b..4cdc8024776 100644 --- a/search/engine/solr/classes/document.php +++ b/search/engine/solr/classes/document.php @@ -196,6 +196,7 @@ class document extends \core_search\document { $data['solr_filecontenthash'] = $file->get_contenthash(); $data['solr_fileindexstatus'] = self::INDEXED_FILE_TRUE; $data['title'] = $file->get_filename(); + $data['modified'] = self::format_time_for_engine($file->get_timemodified()); return $data; } diff --git a/search/engine/solr/classes/engine.php b/search/engine/solr/classes/engine.php index a5c533626ac..68981104f46 100644 --- a/search/engine/solr/classes/engine.php +++ b/search/engine/solr/classes/engine.php @@ -745,7 +745,7 @@ class engine extends \core_search\engine { if (isset($files[$fileid])) { // Check for changes that would mean we need to re-index the file. If so, just leave in $files. // Filelib does not guarantee time modified is updated, so we will check important values. - if ($indexedfile->modified < $files[$fileid]->get_timemodified()) { + if ($indexedfile->modified != $files[$fileid]->get_timemodified()) { continue; } if (strcmp($indexedfile->title, $files[$fileid]->get_filename()) !== 0) { diff --git a/search/engine/solr/tests/engine_test.php b/search/engine/solr/tests/engine_test.php index 8b4265ac828..f2720555aa0 100644 --- a/search/engine/solr/tests/engine_test.php +++ b/search/engine/solr/tests/engine_test.php @@ -393,6 +393,29 @@ class search_solr_engine_testcase extends advanced_testcase { $this->assertRegExp($regex, $exported['content']); } + public function test_export_file_for_engine() { + // Get area to work with. + $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area'); + $area = \core_search\manager::get_search_area($areaid); + + $record = $this->generator->create_record(); + + $doc = $area->get_document($record); + $filerecord = new stdClass(); + $filerecord->timemodified = 978310800; + $file = $this->generator->create_file($filerecord); + $doc->add_stored_file($file); + + $filearray = $doc->export_file_for_engine($file); + + $this->assertEquals(\core_search\manager::TYPE_FILE, $filearray['type']); + $this->assertEquals($file->get_id(), $filearray['solr_fileid']); + $this->assertEquals($file->get_contenthash(), $filearray['solr_filecontenthash']); + $this->assertEquals(\search_solr\document::INDEXED_FILE_TRUE, $filearray['solr_fileindexstatus']); + $this->assertEquals($file->get_filename(), $filearray['title']); + $this->assertEquals(978310800, \search_solr\document::import_time_from_engine($filearray['modified'])); + } + public function test_index_file() { // Very simple test. $file = $this->generator->create_file(); diff --git a/search/tests/generator/lib.php b/search/tests/generator/lib.php index 4abf191a956..a6e99f7d3ea 100644 --- a/search/tests/generator/lib.php +++ b/search/tests/generator/lib.php @@ -194,6 +194,10 @@ class core_search_generator extends component_generator_base { $content = 'File contents'; } + if (isset($options->timemodified)) { + $filerecord['timemodified'] = $options->timemodified; + } + $fs = get_file_storage(); $file = $fs->create_file_from_string($filerecord, $content);