3 * Global Search Engine for Moodle
4 * Michael Champanis (mchampan) [cynnical@gmail.com]
5 * review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
8 * Base search document from which other module/block types can
12 abstract class SearchDocument
extends Zend_Search_Lucene_Document
{
13 public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path) {
14 //document identification and indexing
15 $this->addField(Zend_Search_Lucene_Field
::Keyword('docid', $doc->docid
));
16 //document type : the name of the Moodle element that manages it
17 $this->addField(Zend_Search_Lucene_Field
::Keyword('doctype', $doc->documenttype
));
18 //allows subclassing information from complex modules.
19 $this->addField(Zend_Search_Lucene_Field
::Keyword('itemtype', $doc->itemtype
));
20 //caches the course context.
21 $this->addField(Zend_Search_Lucene_Field
::Keyword('course_id', $course_id));
22 //caches the originator's group.
23 $this->addField(Zend_Search_Lucene_Field
::Keyword('group_id', $group_id));
24 //caches the originator if any
25 $this->addField(Zend_Search_Lucene_Field
::Keyword('user_id', $user_id));
26 // caches the context of this information. i-e, the context in which this information
27 // is being produced/attached. Speeds up the "check for access" process as context in
28 // which the information resides (a course, a module, a block, the site) is stable.
29 $this->addField(Zend_Search_Lucene_Field
::UnIndexed('context_id', $doc->contextid
));
32 $this->addField(Zend_Search_Lucene_Field
::Text('title', $doc->title
));
33 $this->addField(Zend_Search_Lucene_Field
::Text('author', $doc->author
));
34 $this->addField(Zend_Search_Lucene_Field
::UnStored('contents', $doc->contents
));
35 $this->addField(Zend_Search_Lucene_Field
::UnIndexed('url', $doc->url
));
36 $this->addField(Zend_Search_Lucene_Field
::UnIndexed('date', $doc->date
));
38 //additional data added on a per-module basis
39 $this->addField(Zend_Search_Lucene_Field
::Binary('data', serialize($data)));
41 // adding a path allows the document to know where to find specific library calls
42 // for checking access to a module or block content. The Lucene records should only
43 // be responsible to bring back to that call sufficient and consistent information
44 // in order to perform the check.
45 $this->addField(Zend_Search_Lucene_Field
::UnIndexed('path', $path));
47 // adding a capability set required for viewing. -1 if no capability required.
48 // the capability required for viewing is depending on the local situation
49 // of the document. each module should provide this information when pushing
50 // out search document structure. Although capability model should be kept flat
51 // there is no exclusion some module or block developpers use logical combinations
52 // of multiple capabilities in their code. This possibility should be left open here.
53 $this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));