Skip to content

Commit

Permalink
MDL-59459 Golbal Search: Increase file indexing coverage
Browse files Browse the repository at this point in the history
Increase the scope of the files that are detected and
indexed by Moodle's Global Search. This includes intro
and content areas of search areas. The use case here is
in a description for an activity there is a file added
that contains more information about the activity.
It would an advantage to be able to search this content
as well. It would also allow search engine plugins to be
able to index non text files such as images.
  • Loading branch information
Matt Porritt committed Sep 2, 2017
1 parent b3cfb01 commit 4e92156
Show file tree
Hide file tree
Showing 33 changed files with 765 additions and 68 deletions.
37 changes: 37 additions & 0 deletions course/classes/search/mycourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,41 @@ public function get_doc_url(\core_search\document $doc) {
public function get_context_url(\core_search\document $doc) {
return new \moodle_url('/course/view.php', array('id' => $doc->get('courseid')));
}

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

/**
* Return the context info required to index files for
* this search area.
*
* Should be overridden by each search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array(
'overviewfiles',
'summary'// Fileareas.
);

return $fileareas;
}

/**
* Returns the moodle component name.
*
* It might be the plugin name (whole frankenstyle name) or the core subsystem name.
*
* @return string
*/
public function get_component_name() {
return 'course';
}
}
21 changes: 7 additions & 14 deletions mod/assign/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
Expand All @@ -46,22 +47,14 @@ public function uses_file_indexing() {
}

/**
* Add the attached description files.
* Return the context info required to index files for
* this search area.
*
* @param document $document The current document
* @return null
* @return array
*/
public function attach_files($document) {
$fs = get_file_storage();

$cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
$context = \context_module::instance($cm->id);

$files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0,
'sortorder DESC, id ASC', false);
public function get_search_fileareas() {
$fileareas = array('intro', ASSIGN_INTROATTACHMENT_FILEAREA); // Fileareas.

foreach ($files as $file) {
$document->add_stored_file($file);
}
return $fileareas;
}
}
9 changes: 9 additions & 0 deletions mod/book/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
21 changes: 21 additions & 0 deletions mod/book/classes/search/chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,25 @@ public function get_context_url(\core_search\document $doc) {
$contextmodule = \context::instance_by_id($doc->get('contextid'));
return new \moodle_url('/mod/book/view.php', array('id' => $contextmodule->instanceid));
}

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('chapter'); // Filearea.

return $fileareas;
}
}
9 changes: 9 additions & 0 deletions mod/chat/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
9 changes: 9 additions & 0 deletions mod/choice/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
10 changes: 10 additions & 0 deletions mod/data/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

}
9 changes: 9 additions & 0 deletions mod/feedback/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
20 changes: 7 additions & 13 deletions mod/folder/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
Expand All @@ -44,21 +45,14 @@ public function uses_file_indexing() {
}

/**
* Add all the folder files to the index.
* Return the context info required to index files for
* this search area.
*
* @param document $document The current document
* @return null
* @return array
*/
public function attach_files($document) {
$fs = get_file_storage();

$cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
$context = \context_module::instance($cm->id);

$files = $fs->get_area_files($context->id, 'mod_folder', 'content', 0, 'sortorder DESC, id ASC', false);
public function get_search_fileareas() {
$fileareas = array('intro', 'content'); // Fileareas.

foreach ($files as $file) {
$document->add_stored_file($file);
}
return $fileareas;
}
}
9 changes: 9 additions & 0 deletions mod/forum/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
32 changes: 27 additions & 5 deletions mod/forum/classes/search/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ public function uses_file_indexing() {
return true;
}

/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array(
'attachment',
'post'
);

return $fileareas;
}

/**
* Add the forum post attachments.
*
Expand All @@ -142,14 +157,21 @@ public function attach_files($document) {
// Because this is used during indexing, we don't want to cache posts. Would result in memory leak.
unset($this->postsdata[$postid]);

$cm = $this->get_cm('forum', $post->forum, $document->get('courseid'));
$cm = $this->get_cm($this->get_module_name(), $post->forum, $document->get('courseid'));
$context = \context_module::instance($cm->id);
$contextid = $context->id;

$fileareas = $this->get_search_fileareas();
$component = $this->get_component_name();

// Get the files and attach them.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $postid, "filename", false);
foreach ($files as $file) {
$document->add_stored_file($file);
foreach ($fileareas as $filearea) {
$fs = get_file_storage();
$files = $fs->get_area_files($contextid, $component, $filearea, $postid, '', false);

foreach ($files as $file) {
$document->add_stored_file($file);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions mod/glossary/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
21 changes: 21 additions & 0 deletions mod/glossary/classes/search/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,25 @@ protected function get_entry($entryid) {
}
return $this->entriesdata[$entryid];
}

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('attachment', 'entry'); // Fileareas.

return $fileareas;
}
}
9 changes: 9 additions & 0 deletions mod/imscp/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
9 changes: 9 additions & 0 deletions mod/label/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

/**
* Overwritten as labels are displayed in-course.
*
Expand Down
21 changes: 21 additions & 0 deletions mod/lesson/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}

/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('intro', 'page_contents'); // Fileareas.

return $fileareas;
}
}
9 changes: 9 additions & 0 deletions mod/lti/classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
Loading

0 comments on commit 4e92156

Please sign in to comment.