Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Global search brainstorming

From MoodleDocs

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

Moodle 2.3


Global Search is a proposed rewrite of the search mechanism for Moodle 2.3.

Implementation

  • Implemented using Lucene search engine (just like the original global search)
  • Will not require additional DB tables
  • Will allow for partial indexing of the content (e.g. the first time indexer is run, it may only index part of the huge site, and pick up where is left on the next run)
  • Will allow for indexing content from the DB and attachments (e.g. forum post & all attachments)

Modules support

Interface will need to be implemented for a module that wants to be search-able by Global Search. A module will need to:

  • declare that it supports FEATURE_GLOBAL_SEARCH (in function <mod>_supports).
  • implement 3 functions:
    • <mod>_gs_iterator($from = 0)
    • <mod>_gs_get_documents($id)
    • <mod>_page_gs_access($id)

mod_gs_iterator($from=0)

Function has to return moodle recordset with two columns:

  • document set id for this particular module
  • timestamp of the last modification

$from is used to return only documents that were modified after given timestamp. If $from equals 0 then all documents should be returned in the recordset. The meaning of the document set will differ for each module. For example, forum module will return post id as a single document set id. Inside such a document set, there will be several documents, in our case it can be actual forum post and several attachments. Security (access rights) will be managed on the document set level. In this example, you either have or don't have access to both forum post and it's attachments (fixing some bugs like [https://tracker.moodle.org/browse/MDL-29660 MDL-29660] will be required here).

function forum_gs_iterator($from = 0) {
  global $DB;

  $sql = "SELECT id, modified FROM {forum_posts} WHERE modified > ? ORDER BY modified ASC";

  return $DB->get_recordset_sql($sql, array($from));
}