From 56e924061e04eff42919e3e47bc1d55b0e83efe0 Mon Sep 17 00:00:00 2001 From: mchampan Date: Wed, 2 Aug 2006 15:31:59 +0000 Subject: [PATCH] Resource doc type and Zend readme changed. --- search/Zend/IMPORTANT.txt | 7 +-- search/documents/resource_document.php | 60 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 search/documents/resource_document.php diff --git a/search/Zend/IMPORTANT.txt b/search/Zend/IMPORTANT.txt index 56ecab0ccea..d8b80df59e8 100644 --- a/search/Zend/IMPORTANT.txt +++ b/search/Zend/IMPORTANT.txt @@ -1,8 +1,9 @@ We are running cutting-edge (i.e. HEAD) Zend Framework: URL: http://framework.zend.com/svn/framework/trunk - Revision: 696 - Last Changed Rev: 696 - Last Changed Date: 2006-06-23 02:14:54 +0200 (Fri, 23 Jun 2006) + Revision: 924 + Last Changed Rev: 924 + Last Changed Date: 2006-07-27 10:23:04 +0200 (Thu, 27 Jul 2006) + This Zend Framework present in this directory only contains the minimum to run Zend_Search_Lucene - I don't foresee any problems, since the license diff --git a/search/documents/resource_document.php b/search/documents/resource_document.php new file mode 100644 index 00000000000..ee5b6f21c59 --- /dev/null +++ b/search/documents/resource_document.php @@ -0,0 +1,60 @@ +dirroot/search/documents/document.php"); + + class ResourceSearchDocument extends SearchDocument { + public function __construct(&$resource) { + // generic information; required + $doc->docid = $resource['id']; + $doc->title = strip_tags($resource['name']); + + $doc->author = ''; + $doc->contents = strip_tags($resource['summary']).' '.strip_tags($resource['alltext']); + $doc->url = resource_make_link($resource['id']); + + // module specific information; optional + $data = array(); + + // construct the parent class + parent::__construct($doc, $data, SEARCH_TYPE_RESOURCE, $resource['course'], -1); + } //constructor + } //ResourceSearchDocument + + function resource_make_link($resource_id) { + global $CFG; + return $CFG->wwwroot.'/mod/resource/view.php?r='.$resource_id; + } //resource_make_link + + function resource_iterator() { + //trick to leave search indexer functionality intact, but allow + //this document to only use the below function to return info + //to be searched + return array(true); + } //resource_iterator + + //this function does not need a content iterator, returns all the info + //itself; remember to fake the iterator array though + function resource_get_content_for_index(&$notneeded) { + $documents = array(); + + $resources = get_recordset_sql('SELECT * + FROM `resource` + WHERE alltext NOT LIKE "" + AND alltext NOT LIKE " " + AND alltext NOT LIKE " " + AND TYPE != "file"'); + + while (!$resources->EOF) { + $resource = $resources->fields; + + if ($resource) { + $documents[] = new ResourceSearchDocument($resource); + } //if + + $resources->MoveNext(); + } //foreach + + return $documents; + } //resource_get_content_for_index + +?> \ No newline at end of file