diff -Naru GlobalSearch_Original/blocks/search/block_search.php GlobalSearch_Modified/blocks/search/block_search.php --- GlobalSearch_Original/blocks/search/block_search.php 2009-01-08 16:30:17.000000000 +0900 +++ GlobalSearch_Modified/blocks/search/block_search.php 2009-07-06 18:44:12.000000000 +0900 @@ -57,6 +57,10 @@ '
' . '' . '' +// (Shirai155): using courseid (2009/06/27) +// (Shirai155): Add from here + . '' +// (Shirai155): Add to here . '' . '
'; } else { diff -Naru GlobalSearch_Original/search/documents/forum_document.php GlobalSearch_Modified/search/documents/forum_document.php --- GlobalSearch_Original/search/documents/forum_document.php 2009-06-05 09:48:14.000000000 +0900 +++ GlobalSearch_Modified/search/documents/forum_document.php 2009-07-06 20:43:00.000000000 +0900 @@ -56,15 +56,84 @@ } } +// (Shirai152): dealing with a attachment file of forum post (2009/06/26) +// (Shirai152): Add from here (based upon class UserBlogAttachmentSearchDocument (user_document.php) +/** +* a class for representing searchable information in user metadata +* +*/ +// (Shirai152): modified from here +// class UserBlogAttachmentSearchDocument extends SearchDocument { +class ForumAttachmentSearchDocument extends SearchDocument { +// (Shirai152): modified to here + + /** + * constructor + */ +// (Shirai152): modified from here +// public function __construct(&$post, $context_id) { + public function __construct(&$post, $forum_id, $course_id, $context_id) { +// (Shirai152): modified to here + // generic information; required + $doc->docid = $post['id']; +// (Shirai152): add from here +// $doc->documenttype = SEARCH_TYPE_USER; + $doc->documenttype = SEARCH_TYPE_FORUM; +// (Shirai152): add to here + $doc->itemtype = 'attachment'; + $doc->contextid = $context_id; + + $user = get_record('user', 'id', $post['userid']); + + // we cannot call userdate with relevant locale at indexing time. + $doc->title = get_string('file').' : '.$post['subject']; + $doc->date = $post['created']; + + //remove '(ip.ip.ip.ip)' from chat author list + $doc->author = fullname($user); + $doc->contents = $post['message'].' '.$post['alltext']; +// (Shirai152): modified from here +// $doc->url = user_make_link($post['id'], 'attachment'); + $doc->url = forum_make_link($post['discussion'], $post['id'], 'attachment'); +// (Shirai152): modified to here +// (Shirai152):add from here + $doc->url .= '/'.$post['directfile']; + if (!empty($post['filename'])) { + $additional_keyset['filename'] = $post['filename']; + } else $additional_keyset = null; + + // module specific information + $data->forum = $forum_id; + $data->discussion = $post['discussion']; +// (Shirai152): add to here + + // module specific information; optional + + // construct the parent class +// (Shirai152): modified from here +// parent::__construct($doc, $data, 0, 0, $post['userid'], PATH_FOR_SEARCH_TYPE_USER); + parent::__construct($doc, $data, $course_id, $post['groupid'], $post['userid'], 'mod/'.PATH_FOR_SEARCH_TYPE_FORUM, $additional_keyset); +// (Shirai152): modified to here + } +} +// (Shirai152): add to here /** * constructs a valid link to a chat content * @param discussion_id the discussion * @param post_id the id of a single post * @return a well formed link to forum message display */ -function forum_make_link($discussion_id, $post_id) { +// (Shirai152): modified from here +// function forum_make_link($discussion_id, $post_id) { +function forum_make_link($discussion_id, $post_id, $itemtype = 'post') { +// (Shirai152): modified to here global $CFG; +// (Shirai152): add from here + if ($itemtype == 'attachment') { + return $CFG->wwwroot.'/file.php'; + } +// (Shirai152): add to here return $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion_id.'#'.$post_id; } @@ -83,6 +152,9 @@ * @return an array of searchable documents */ function forum_get_content_for_index(&$forum) { +// (Shirai152): add from here + global $CFG; +// (Shirai152): add to here $documents = array(); if (!$forum) return $documents; @@ -100,6 +172,14 @@ if ($aPost) { if (!empty($aPost->message)) { echo "*"; +// (Shirai152): add from here + // record the attachment if any and physical files can be indexed + if (@$CFG->block_search_enable_file_indexing){ + if ($aPost->attachment){ + forum_get_physical_file($aPost, $context->id, false, $documents); + } + } +// (Shirai152): add to here $documents[] = new ForumSearchDocument(get_object_vars($aPost), $forum->id, $forum->course, 'head', $context->id); } if ($children = forum_get_child_posts_fast($aPost->id, $forum->id)) { @@ -107,6 +187,14 @@ echo "."; $aChild->itemtype = 'post'; if (strlen($aChild->message) > 0) { +// (Shirai152): add from here + // record the attachment if any and physical files can be indexed + if (@$CFG->block_search_enable_file_indexing){ + if ($aChild->attachment){ + forum_get_physical_file($aChild, $context->id, false, $documents); + } + } +// (Shirai152): add to here $documents[] = new ForumSearchDocument(get_object_vars($aChild), $forum->id, $forum->course, 'post', $context->id); } } @@ -117,6 +205,91 @@ return $documents; } +// (Shirai152): add from here based upon user_document.php,function user_get_physical_file() +/** +* get text from a physical file +* @param object $post a post to whech the file is attached to +* @param boolean $context_id if in future we need recording a context along with the search document, pass it here +* @param boolean $getsingle if true, returns a single search document, elsewhere return the array +* given as documents increased by one +* @param array $documents the array of documents, by ref, where to add the new document. +* @return a search document when unique or false. +*/ +// (Shirai152): modified from here +// function user_get_physical_file(&$post, $context_id, $getsingle, &$documents = null){ +function forum_get_physical_file(&$post, $context_id, $getsingle, &$documents = null){ +// (Shirai152): modified to here + global $CFG; + + // cannot index empty references + if (empty($post->attachment)){ + mtrace("Cannot index, empty reference."); + return false; + } + + $fileparts = pathinfo($post->attachment); + // cannot index unknown or masked types + if (empty($fileparts['extension'])) { + mtrace("Cannot index without explicit extension."); + return false; + } + + // cannot index non existent file +// (Shirai152): modified from here +// $file = "{$CFG->dataroot}/blog/attachments/{$post->id}/{$post->attachment}"; + $file = "{$CFG->dataroot}/{$post->course}/moddata/forum/{$post->forum}/{$post->id}/{$post->attachment}"; +// (Shirai152): modified to here + if (!file_exists($file)){ + mtrace("Missing attachment file $file : will not be indexed."); + return false; + } + + $ext = strtolower($fileparts['extension']); + + // cannot index unallowed or unhandled types + if (!preg_match("/\b$ext\b/i", $CFG->block_search_filetypes)) { + mtrace($fileparts['extension'] . ' is not an allowed extension for indexing'); + return false; + } + if (file_exists($CFG->dirroot.'/search/documents/physical_'.$ext.'.php')){ + include_once($CFG->dirroot.'/search/documents/physical_'.$ext.'.php'); + $function_name = 'get_text_for_indexing_'.$ext; +// (Shirai152): modified from here +// $directfile = "blog/attachments/{$post->id}/{$post->attachment}"; + $directfile = "{$post->course}/moddata/forum/{$post->forum}/{$post->id}/{$post->attachment}"; +// (Shirai152): modified to here + $post->alltext = $function_name($post, $directfile); + if (!empty($post->alltext)){ +// (Shirai152): add from here + $post->filename = basename($post->attachment); +// (Shirai152): add to here + if ($getsingle){ + $posthash = get_object_vars($post); +// (Shirai152): modified from here +// $single = new UserBlogAttachmentSearchDocument($posthash, $context_id); + $single = new ForumAttachmentSearchDocument($posthash, $post->forum, $post->course, $context_id); +// mtrace("finished attachment {$post->attachment} in {$post->title}"); + mtrace("finished attachment {$post->attachment} in {$post->subject}"); +// (Shirai152): modified to here + return $single; + } else { +// (Shirai152): add from here + $post->directfile = $directfile; +// (Shirai152): add to here + $posthash = get_object_vars($post); +// (Shirai152): modified from here +// $documents[] = new UserBlogAttachmentSearchDocument($posthash, $context_id); + $documents[] = new ForumAttachmentSearchDocument($posthash, $post->forum, $post->course, $context_id); +// (Shirai152): modified to here + } + mtrace("finished attachment {$post->attachment} in {$post->subject}"); + } + } else { + mtrace("fulltext handler not found for $ext type"); + } + return false; +} +// (Shirai152): add tohere /** * returns a single forum search document based on a forum entry id * @param id an id for a single information stub @@ -132,6 +305,14 @@ if ($cm){ $context = get_context_instance(CONTEXT_MODULE, $cm->id); $post->groupid = $discussion->groupid; +// (Shirai152): add from here + if (($itemtype == 'attachment') && @$CFG->block_search_enable_file_indexing) { + if ($post->attachment){ +// return forum_get_physical_file($post, null, true); + return forum_get_physical_file($post, $context->id, true); + } + } // else : 'head' or 'post' +// (Shirai152): add to here return new ForumSearchDocument(get_object_vars($post), $discussion->forum, $discussion->course, $itemtype, $context->id); } return null; @@ -182,6 +363,7 @@ } } +// (Shirai152): add p.attachment, p.subject, d.course, d.forum $query = " SELECT p.id, @@ -192,7 +374,11 @@ d.groupid, p.userid, u.firstname, - u.lastname + u.lastname, + p.attachment, + p.subject, + d.course, + d.forum FROM {$CFG->prefix}forum_discussions d JOIN @@ -223,6 +409,7 @@ function forum_get_child_posts_fast($parent, $forum_id) { global $CFG; +// (Shirai152): add p.attachment, p.subject, d.course, d.forum $query = " SELECT p.id, @@ -234,7 +421,11 @@ p.userid, d.groupid, u.firstname, - u.lastname + u.lastname, + p.attachment, + p.subject, + d.course, + d.forum FROM {$CFG->prefix}forum_discussions d JOIN diff -Naru GlobalSearch_Original/search/documents/resource_document.php GlobalSearch_Modified/search/documents/resource_document.php --- GlobalSearch_Original/search/documents/resource_document.php 2009-06-25 16:09:09.000000000 +0900 +++ GlobalSearch_Modified/search/documents/resource_document.php 2009-07-06 20:42:37.000000000 +0900 @@ -36,6 +36,10 @@ $doc->contextid = $context_id; $doc->title = strip_tags($resource['name']); +// (Shirai153): adding 'file:' to the head of title when the result of search is a file (2009/06/27) +// (Shirai153): add from here + if ($resource['type'] == 'file') $doc->title = get_string('file').' : '.$doc->title; +// (Shirai153): add to here $doc->date = $resource['timemodified']; $doc->author = ''; $doc->contents = strip_tags($resource['summary']).' '.strip_tags($resource['alltext']); @@ -45,7 +49,15 @@ $data = array(); // construct the parent class - parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE); +// (Shirai149): dealing with a filename of resource as search keyword and also displaying it (2009/06/10) +// (Shirai149): comment out from here +// parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE); +// (Shirai149): add from here + if (!empty($resource['filename'])) { + $additional_keyset['filename'] = $resource['filename']; + } else $additional_keyset = null; + parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE, $additional_keyset); +// (Shirai149): add to here } //constructor } //ResourceSearchDocument @@ -199,6 +211,10 @@ $function_name = 'get_text_for_indexing_'.$ext; $resource->alltext = $function_name($resource); if (!empty($resource->alltext)){ +// (Shirai149): dealing with a filename of resource as search keyword and also displaying it (2009/06/10) +// (Shirai149): add from here + $resource->filename = basename($resource->reference); +// (Shirai149): add to here if ($getsingle){ $single = new ResourceSearchDocument(get_object_vars($resource), $context_id); mtrace("finished file $resource->name as {$resource->reference}"); @@ -258,7 +274,11 @@ $cm = get_record('course_modules', 'id', $resource->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($resource->type == 'file' && @$CFG->block_search_enable_file_indexing){ - $document = resource_get_physical_file($resource, true, $context->id); +// (Debug008): miss order of arguments (2009/06/04) +// (Debug008): modified from here +// $document = resource_get_physical_file($resource, true, $context->id); + $document = resource_get_physical_file($resource, $context->id, true); +// (Debug008): modified to here if (!$document) mtrace("Warning : this document {$resource->name} will not be indexed"); return $document; } else { diff -Naru GlobalSearch_Original/search/query.php GlobalSearch_Modified/search/query.php --- GlobalSearch_Original/search/query.php 2009-06-05 09:48:14.000000000 +0900 +++ GlobalSearch_Modified/search/query.php 2009-07-06 20:46:45.000000000 +0900 @@ -57,6 +57,10 @@ $pages = ($page_number == -1) ? false : true; $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; $query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN)); +// (Shirai155): using courseid (2009/06/27) +// (Shirai155): Add from here + $courseid = optional_param('id', SITEID, PARAM_INT); +// (Shirai155): Add to here /// discard harmfull searches @@ -191,11 +195,23 @@ ?>
+ +     - | + + "> | - +
| + "> |  
@@ -366,7 +388,14 @@ ."'>$icon $listing->title $course
\n"; // print "
  • url)."'>$listing->title
    \n" // ."".search_shorten_url($listing->url, 70)."
    \n" - echo "{$typestr}: " . $listing->doctype . ", {$scorestr}: " . round($listing->score, 3); +// (Shirai149): dealing with a filename of resource as search keyword and also displaying it (2009/06/10) +// (Shirai149): comment out from here +// echo "{$typestr}: " . $listing->doctype . ", {$scorestr}: " . round($listing->score, 3); +// (Shirai149): add from here + echo "{$typestr}: " . $listing->doctype; + if (!empty($listing->filename)) echo " ({$listing->filename}) "; + echo ", {$scorestr}: " . round($listing->score, 3); +// (Shirai149): add to here if (!empty($listing->author) && !is_numeric($listing->author)){ echo ", {$authorstr}: ".$listing->author."\n" ."
  • \n"; @@ -388,5 +417,15 @@ \ No newline at end of file diff -Naru GlobalSearch_Original/search/querylib.php GlobalSearch_Modified/search/querylib.php --- GlobalSearch_Original/search/querylib.php 2009-06-05 09:48:14.000000000 +0900 +++ GlobalSearch_Modified/search/querylib.php 2009-07-06 20:47:56.000000000 +0900 @@ -270,16 +270,44 @@ if ($this->can_display($USER, $hit->docid, $hit->doctype, $hit->course_id, $hit->group_id, $hit->path, $hit->itemtype, $hit->context_id, $searchables )) { if ($i >= ($page - 1) * $this->results_per_page){ $resultdoc->number = $realindex; - $resultdoc->url = $hit->url; - $resultdoc->title = $hit->title; +// (Shirai149): dealing with a filename of resource as search keyword and also displaying it (2009/06/10) +// (Shirai149): comment out from here +// $resultdoc->url = $hit->url; +// $resultdoc->title = $hit->title; +// $resultdoc->score = $hit->score; +// $resultdoc->doctype = $hit->doctype; +// $resultdoc->author = $hit->author; +// $resultdoc->courseid = $hit->course_id; +// $resultdoc->userid = $hit->user_id; +// (Shirai149): add from here $resultdoc->score = $hit->score; - $resultdoc->doctype = $hit->doctype; - $resultdoc->author = $hit->author; - $resultdoc->courseid = $hit->course_id; - $resultdoc->userid = $hit->user_id; + $doc = $hit->getDocument(); + $fieldnames = $doc->getFieldNames(); + foreach ($fieldnames as $fieldname) { + $resultdoc->$fieldname = $hit->$fieldname; + } + // not match + $resultdoc->courseid = $resultdoc->course_id; + unset($resultdoc->course_id); + $resultdoc->userid = $resultdoc->user_id; + unset($resultdoc->user_id); + // No need? + unset($resultdoc->docid); + unset($resultdoc->itemtype); + unset($resultdoc->groupid); + unset($resultdoc->context_id); + unset($resultdoc->date); + unset($resultdoc->data); + unset($resultdoc->path); + unset($resultdoc->dbid); +// (Shirai149): add to here //and store it $resultdocs[] = clone($resultdoc); +// (Shirai149): add from here + unset($resultdoc); + $resultdoc = new SearchResult(); +// (Shirai149): add to here } $realindex++; } else { diff -Naru GlobalSearch_Original/search/searchtypes.php GlobalSearch_Modified/search/searchtypes.php --- GlobalSearch_Original/search/searchtypes.php 2009-01-08 16:30:17.000000000 +0900 +++ GlobalSearch_Modified/search/searchtypes.php 2009-07-06 18:47:31.000000000 +0900 @@ -30,5 +30,8 @@ define('SEARCH_EXTRAS', 'user'); define('SEARCH_TYPE_USER', 'user'); define('PATH_FOR_SEARCH_TYPE_USER', 'user'); - +// (Shirai152): dealing with a attachment file of forum post (2009/06/26) +// (Shirai152): Add from here +define('PATH_FOR_SEARCH_TYPE_FORUM', 'forum'); +// (Shirai152): Add to here ?> \ No newline at end of file