MDL-55725 search: Index proper time modified with indexed files
authorEric Merrill <merrill@oakland.edu>
Wed, 7 Sep 2016 21:13:46 +0000 (17:13 -0400)
committerEric Merrill <merrill@oakland.edu>
Wed, 7 Sep 2016 21:33:28 +0000 (17:33 -0400)
search/engine/solr/classes/document.php
search/engine/solr/classes/engine.php
search/engine/solr/tests/engine_test.php
search/tests/generator/lib.php

index 34760f0..4cdc802 100644 (file)
@@ -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;
     }
index a5c5336..6898110 100644 (file)
@@ -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) {
index 8b4265a..f272055 100644 (file)
@@ -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();
index 4abf191..a6e99f7 100644 (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);