mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-55725 search: Index proper time modified with indexed files
This commit is contained in:
parent
5c33a0db21
commit
1aaead91f9
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user