This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.php
75 lines (69 loc) · 3.78 KB
/
document.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Global Search Engine for Moodle
*
* @package search
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 1.8
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
* Base search document from which other module/block types can
* extend.
*/
/**
*
*/
abstract class SearchDocument extends Zend_Search_Lucene_Document {
public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
//document identification and indexing
$this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid));
//document type : the name of the Moodle element that manages it
$this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $doc->documenttype));
//allows subclassing information from complex modules.
$this->addField(Zend_Search_Lucene_Field::Keyword('itemtype', $doc->itemtype));
//caches the course context.
$this->addField(Zend_Search_Lucene_Field::Keyword('course_id', $course_id));
//caches the originator's group.
$this->addField(Zend_Search_Lucene_Field::Keyword('group_id', $group_id));
//caches the originator if any
$this->addField(Zend_Search_Lucene_Field::Keyword('user_id', $user_id));
// caches the context of this information. i-e, the context in which this information
// is being produced/attached. Speeds up the "check for access" process as context in
// which the information resides (a course, a module, a block, the site) is stable.
$this->addField(Zend_Search_Lucene_Field::UnIndexed('context_id', $doc->contextid));
//data for document
$this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title));
$this->addField(Zend_Search_Lucene_Field::Text('author', $doc->author));
$this->addField(Zend_Search_Lucene_Field::UnStored('contents', $doc->contents));
$this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $doc->url));
$this->addField(Zend_Search_Lucene_Field::UnIndexed('date', $doc->date));
//additional data added on a per-module basis
$this->addField(Zend_Search_Lucene_Field::Binary('data', serialize($data)));
// adding a path allows the document to know where to find specific library calls
// for checking access to a module or block content. The Lucene records should only
// be responsible to bring back to that call sufficient and consistent information
// in order to perform the check.
$this->addField(Zend_Search_Lucene_Field::UnIndexed('path', $path));
/*
// adding a capability set required for viewing. -1 if no capability required.
// the capability required for viewing is depending on the local situation
// of the document. each module should provide this information when pushing
// out search document structure. Although capability model should be kept flat
// there is no exclusion some module or block developpers use logical combinations
// of multiple capabilities in their code. This possibility should be left open here.
$this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
*/
/*
// Additional key set allows a module to ask for extensible criteria based search
// depending on the module internal needs.
*/
if (!empty($additional_keyset)){
foreach($additional_keyset as $keyname => $keyvalue){
$this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue));
}
}
}
}
?>