Skip to content

Commit

Permalink
MDL-55725 search: Index proper time modified with indexed files
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill committed Sep 7, 2016
1 parent c265709 commit 937ddb9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions search/engine/solr/classes/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function export_file_for_engine($file) {
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion search/engine/solr/classes/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ protected function process_document_files($document) {
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) {
Expand Down
23 changes: 23 additions & 0 deletions search/engine/solr/tests/engine_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,29 @@ public function test_highlight($fileindexing) {
$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();
Expand Down
4 changes: 4 additions & 0 deletions search/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ public function create_file($options = null) {
$content = 'File contents';
}

if (isset($options->timemodified)) {
$filerecord['timemodified'] = $options->timemodified;
}

$fs = get_file_storage();
$file = $fs->create_file_from_string($filerecord, $content);

Expand Down

0 comments on commit 937ddb9

Please sign in to comment.