Commit 4e921569 authored by Matt Porritt's avatar Matt Porritt
Browse files

MDL-59459 Golbal Search: Increase file indexing coverage

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.
parent b3cfb013
......@@ -124,4 +124,41 @@ class mycourse extends \core_search\base {
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';
}
}
......@@ -36,6 +36,7 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
* @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.
*
......@@ -46,22 +47,14 @@ class activity extends \core_search\base_activity {
}
/**
* 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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -158,4 +158,25 @@ class chapter extends \core_search\base_mod {
$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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,4 +34,14 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,6 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @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.
*
......@@ -44,21 +45,14 @@ class activity extends \core_search\base_activity {
}
/**
* 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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -120,6 +120,21 @@ class post extends \core_search\base_mod {
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.
*
......@@ -142,14 +157,21 @@ class post extends \core_search\base_mod {
// 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);
}
}
}
......
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -193,4 +193,25 @@ class entry extends \core_search\base_mod {
}
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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -38,6 +38,15 @@ defined('MOODLE_INTERNAL') || die();
*/
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.
*
......
......@@ -34,4 +34,25 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -35,7 +35,6 @@ defined('MOODLE_INTERNAL') || die();
*/
class activity extends \core_search\base_activity {
/**
* Returns the document associated with this activity.
*
......@@ -74,4 +73,25 @@ class activity extends \core_search\base_activity {
return $doc;
}
/**
* 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', 'content'); // Fileareas.
return $fileareas;
}
}
......@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
* @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;
}
}
......@@ -34,6 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @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.
*
......@@ -44,24 +45,14 @@ class activity extends \core_search\base_activity {
}
/**
* Add the main file 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);
public function get_search_fileareas() {
$fileareas = array('intro', 'content'); // Fileareas.
// Order by sortorder desc, the first is consided the main file.
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
$mainfile = $files ? reset($files) : null;
if ($mainfile && $mainfile->get_sortorder() > 0) {
$document->add_stored_file($mainfile);
}
return $fileareas;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment