/search/documents/document.php

https://github.com/jarednipper/HSU-common-code · PHP · 136 lines · 26 code · 10 blank · 100 comment · 1 complexity · 75160b86ddb1812bd28310fdd5cb0e39 MD5 · raw file

  1. <?php
  2. /**
  3. * Global Search Engine for Moodle
  4. *
  5. * @package search
  6. * @category core
  7. * @subpackage document_wrappers
  8. * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9. * @contributor Tatsuva Shirai on UTF-8 multibyte fixing
  10. * @date 2008/03/31
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  12. *
  13. * Base search document from which other module/block types can
  14. * extend.
  15. */
  16. /**
  17. *
  18. */
  19. abstract class SearchDocument extends Zend_Search_Lucene_Document {
  20. public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
  21. $encoding = 'UTF-8';
  22. //document identification and indexing
  23. $this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid, $encoding));
  24. //document type : the name of the Moodle element that manages it
  25. $this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $doc->documenttype, $encoding));
  26. //allows subclassing information from complex modules.
  27. $this->addField(Zend_Search_Lucene_Field::Keyword('itemtype', $doc->itemtype, $encoding));
  28. //caches the course context.
  29. $this->addField(Zend_Search_Lucene_Field::Keyword('course_id', $course_id, $encoding));
  30. //caches the originator's group.
  31. $this->addField(Zend_Search_Lucene_Field::Keyword('group_id', $group_id, $encoding));
  32. //caches the originator if any
  33. $this->addField(Zend_Search_Lucene_Field::Keyword('user_id', $user_id, $encoding));
  34. // caches the context of this information. i-e, the context in which this information
  35. // is being produced/attached. Speeds up the "check for access" process as context in
  36. // which the information resides (a course, a module, a block, the site) is stable.
  37. $this->addField(Zend_Search_Lucene_Field::UnIndexed('context_id', $doc->contextid, $encoding));
  38. //data for document
  39. $this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title, $encoding));
  40. $this->addField(Zend_Search_Lucene_Field::Text('author', $doc->author, $encoding));
  41. $this->addField(Zend_Search_Lucene_Field::UnStored('contents', $doc->contents, $encoding));
  42. $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $doc->url, $encoding));
  43. $this->addField(Zend_Search_Lucene_Field::UnIndexed('date', $doc->date, $encoding));
  44. //additional data added on a per-module basis
  45. $this->addField(Zend_Search_Lucene_Field::Binary('data', serialize($data)));
  46. // adding a path allows the document to know where to find specific library calls
  47. // for checking access to a module or block content. The Lucene records should only
  48. // be responsible to bring back to that call sufficient and consistent information
  49. // in order to perform the check.
  50. $this->addField(Zend_Search_Lucene_Field::UnIndexed('path', $path, $encoding));
  51. /*
  52. // adding a capability set required for viewing. -1 if no capability required.
  53. // the capability required for viewing is depending on the local situation
  54. // of the document. each module should provide this information when pushing
  55. // out search document structure. Although capability model should be kept flat
  56. // there is no exclusion some module or block developpers use logical combinations
  57. // of multiple capabilities in their code. This possibility should be left open here.
  58. $this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
  59. */
  60. /*
  61. // Additional key set allows a module to ask for extensible criteria based search
  62. // depending on the module internal needs.
  63. */
  64. if (!empty($additional_keyset)){
  65. foreach($additional_keyset as $keyname => $keyvalue){
  66. $this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue, $encoding));
  67. }
  68. }
  69. }
  70. }
  71. /*
  72. abstract class SearchDocument extends Zend_Search_Lucene_Document {
  73. public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
  74. //document identification and indexing
  75. $this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid));
  76. //document type : the name of the Moodle element that manages it
  77. $this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $doc->documenttype));
  78. //allows subclassing information from complex modules.
  79. $this->addField(Zend_Search_Lucene_Field::Keyword('itemtype', $doc->itemtype));
  80. //caches the course context.
  81. $this->addField(Zend_Search_Lucene_Field::Keyword('course_id', $course_id));
  82. //caches the originator's group.
  83. $this->addField(Zend_Search_Lucene_Field::Keyword('group_id', $group_id));
  84. //caches the originator if any
  85. $this->addField(Zend_Search_Lucene_Field::Keyword('user_id', $user_id));
  86. // caches the context of this information. i-e, the context in which this information
  87. // is being produced/attached. Speeds up the "check for access" process as context in
  88. // which the information resides (a course, a module, a block, the site) is stable.
  89. $this->addField(Zend_Search_Lucene_Field::UnIndexed('context_id', $doc->contextid));
  90. //data for document
  91. $this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title));
  92. $this->addField(Zend_Search_Lucene_Field::Text('author', $doc->author));
  93. $this->addField(Zend_Search_Lucene_Field::UnStored('contents', $doc->contents));
  94. $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $doc->url));
  95. $this->addField(Zend_Search_Lucene_Field::UnIndexed('date', $doc->date));
  96. //additional data added on a per-module basis
  97. $this->addField(Zend_Search_Lucene_Field::Binary('data', serialize($data)));
  98. // adding a path allows the document to know where to find specific library calls
  99. // for checking access to a module or block content. The Lucene records should only
  100. // be responsible to bring back to that call sufficient and consistent information
  101. // in order to perform the check.
  102. $this->addField(Zend_Search_Lucene_Field::UnIndexed('path', $path));
  103. /*
  104. // adding a capability set required for viewing. -1 if no capability required.
  105. // the capability required for viewing is depending on the local situation
  106. // of the document. each module should provide this information when pushing
  107. // out search document structure. Although capability model should be kept flat
  108. // there is no exclusion some module or block developpers use logical combinations
  109. // of multiple capabilities in their code. This possibility should be left open here.
  110. $this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
  111. */
  112. /*
  113. // Additional key set allows a module to ask for extensible criteria based search
  114. // depending on the module internal needs.
  115. *
  116. if (!empty($additional_keyset)){
  117. foreach($additional_keyset as $keyname => $keyvalue){
  118. $this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue));
  119. }
  120. }
  121. }
  122. }*/
  123. ?>