Skip to content

Commit

Permalink
global search MDL-24625 fixed up global search regressions so that in…
Browse files Browse the repository at this point in the history
…dexing will complete successfully.
  • Loading branch information
nebgor committed Oct 26, 2010
1 parent 0d804f2 commit 6cd2c7f
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 53 deletions.
25 changes: 18 additions & 7 deletions search/documents/assignment_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AssignmentSearchDocument extends SearchDocument {
/**
* constructor
*/
public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id) {
public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id , $submissionoffset = null) {
// generic information; required
$doc->docid = $assignmentitem['id'];
$doc->documenttype = SEARCH_TYPE_ASSIGNMENT;
Expand All @@ -43,8 +43,13 @@ public function __construct(&$assignmentitem, $assignment_module_id, $itemtype,

//remove '(ip.ip.ip.ip)' from chat author list
$doc->author = $assignmentitem['authors'];
$doc->contents = $assignmentitem['description'];
$doc->url = assignment_make_link($assignment_module_id, $itemtype, $owner_id);
if ($itemtype == 'intro') {
$doc->contents = $assignmentitem['intro'];
$doc->url = assignment_make_link($assignment_module_id, $itemtype, $owner_id);
} else {
$doc->contents = $assignmentitem['data1'];
$doc->url = assignment_make_link($assignment_module_id, $itemtype, $owner_id, $submissionoffset);
}

// module specific information; optional
$data->assignment = $assignment_module_id;
Expand All @@ -64,11 +69,15 @@ public function __construct(&$assignmentitem, $assignment_module_id, $itemtype,
* @uses CFG
* @return a well formed link to session display
*/
function assignment_make_link($cm_id, $itemtype, $owner) {
function assignment_make_link($cm_id, $itemtype, $owner, $submissionoffset=null) {
global $CFG;

if ($itemtype == 'description')
if ($itemtype == 'intro') {
return $CFG->wwwroot.'/mod/assignment/view.php?id='.$cm_id;
} else {
return $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$cm_id.'&userid='.$owner.'&mode=single&offset='.$submissionoffset;
//?id=80&userid=4&mode=single&filter=0&offset=1
}
}

/**
Expand Down Expand Up @@ -102,11 +111,13 @@ function assignment_get_content_for_index(&$assignment) {

$assignment->authors = '';
$assignment->date = $assignment->timemodified;
$documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'description', $assignment->course, null, $context->id);
$documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'intro', $assignment->course, null, $context->id);

$submissions = assignment_get_all_submissions($assignment);
if ($submissions){
$submissionoffset=-1;
foreach($submissions as $submission){
$submissionoffset++;
$owner = $DB->get_record('user', array('id' => $submission->userid));
$submission->authors = fullname($owner);
$submission->assignmenttype = $assignment->assignmenttype;
Expand Down Expand Up @@ -140,7 +151,7 @@ function assignment_get_content_for_index(&$assignment) {
if ($submitted->source = 'text'){
$submission->description = $submitted->data;
$submission->description = preg_replace("/<[^>]*>/", '', $submission->description); // stip all tags
$documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id);
$documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id, $submissionoffset);
mtrace("finished online submission for {$submission->authors} in assignment {$assignment->name}");
} elseif ($submitted->source = 'files'){
$SUBMITTED = opendir($submitted->path);
Expand Down
2 changes: 1 addition & 1 deletion search/documents/chat_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
$fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
$totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
$tracks = array();
$messages = $DB->get_records_select('chat_messages', "chatid = ':chatid' :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
$messages = $DB->get_records_select('chat_messages', "chatid = :chatid :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
if ($messages){
// splits discussions against groups
$groupedMessages = array();
Expand Down
13 changes: 6 additions & 7 deletions search/documents/data_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,15 @@ function data_get_comments($database_id) {
c.id,
r.groupid,
c.userid,
c.recordid,
c.itemid,
c.content,
c.created,
c.modified,
c.timecreated,
r.dataid
FROM
{data_comments} as c,
{data_records} as r
{data_records} as r
JOIN
{comments} as c ON c.contextid = r.id
WHERE
c.recordid = r.id AND
r.dataid = ?
";
$comments = $DB->get_records_sql($query, array($database_id));
Expand Down Expand Up @@ -232,7 +231,7 @@ function data_get_content_for_index(&$database) {
$records_comments = data_get_comments($database->id);
if ($records_comments){
foreach($records_comments as $aComment){
$aComment->title = $recordsTitle[$aComment->recordid];
$aComment->title = $recordsTitle[$aComment->itemid];
$authoruser = $DB->get_record('user', array('id' => $aComment->userid));
$aComment->author = fullname($authoruser);
$documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
Expand Down
18 changes: 13 additions & 5 deletions search/documents/glossary_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ public function __construct(&$entry, $glossary_id, $course_id, $context_id) {
global $DB;

// generic information; required
$doc->docid = $entry['id'];
$doc->docid = $entry['itemid'];
$doc->documenttype = SEARCH_TYPE_GLOSSARY;
$doc->itemtype = 'comment';
$doc->contextid = $context_id;

$doc->title = get_string('commenton', 'search') . ' ' . $entry['concept'];
$doc->date = $entry['timemodified'];
$doc->date = $entry['timecreated'];

if ($entry['userid'])
$user = $DB->get_record('user', array('id' => $entry['userid']));
$doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
$doc->contents = strip_tags($entry['entrycomment']);
$doc->url = glossary_make_link($entry['entryid']);
$doc->contents = strip_tags($entry['content']);
$doc->url = glossary_make_link($entry['itemid']);

// module specific information; optional
$data->glossary = $glossary_id;
Expand All @@ -104,6 +104,7 @@ public function __construct(&$entry, $glossary_id, $course_id, $context_id) {
*/
function glossary_make_link($entry_id) {
global $CFG;
require_once($CFG->dirroot.'/search/querylib.php');

//links directly to entry
// return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id;
Expand Down Expand Up @@ -158,7 +159,14 @@ function glossary_get_content_for_index(&$glossary) {

// index comments
if (count($entryIds)){
$comments = $DB->get_records_list('glossary_comments', 'entryid', $entryIds);
list($entryidssql, $params) = $DB->get_in_or_equal($entryIds, SQL_PARAMS_NAMED);
$params['ctxid'] = $context->id;
$sql = "SELECT *
FROM {comments}
WHERE contextid = :ctxid
AND itemid $entryidssql";
$comments = $DB->get_recordset_sql($sql, $params);

if ($comments){
foreach($comments as $comment) {
if (strlen($comment->entrycomment) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion search/documents/label_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(&$label, $context_id) {
$doc->title = strip_tags($label['name']);
$doc->date = $label['timemodified'];
$doc->author = '';
$doc->contents = strip_tags($label['content']);
$doc->contents = strip_tags($label['intro']);
$doc->url = label_make_link($label['course']);

// module specific information; optional
Expand Down
23 changes: 16 additions & 7 deletions search/documents/resource_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,28 @@ function resource_iterator() {
function resource_get_content_for_index(&$notneeded) {
global $CFG, $DB;


// starting with Moodle native resources
$documents = array();

$dbman = $DB->get_manager();
if (!$dbman->table_exists('resource_old')) {
return $documents;
}

// the resources have been moved into modules of their own. indexing need to be created for these.
// for a temporary fix (until MDL-24856 is fixed) pointing this query to a table that is copy of the old resource table schema.
$query = "
SELECT
id as trueid,
r.*
FROM
{resource} as r
WHERE
alltext != '' AND
alltext != ' ' AND
alltext != '&nbsp;' AND
type != 'file'
{resource_old} as r
WHERE
alltext != '' AND
alltext != ' ' AND
alltext != '&nbsp;' AND
type != 'file'
";
if ($resources = $DB->get_records_sql($query)){
foreach($resources as $aResource){
Expand Down Expand Up @@ -127,7 +136,7 @@ function resource_get_content_for_index(&$notneeded) {
r.type as type,
r.timemodified as timemodified
FROM
{resource} as r,
{resource_old} as r,
{course_modules} as cm,
{modules} as m
WHERE
Expand Down
43 changes: 24 additions & 19 deletions search/documents/wiki_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function __construct(&$page, $wiki_id, $course_id, $group_id, $user_id, $
$doc->itemtype = 'standard';
$doc->contextid = $context_id;

$doc->title = $page['pagename'];
$doc->date = $page['lastmodified'];
$doc->title = $page['title'];
$doc->date = $page['timemodified'];
//remove '(ip.ip.ip.ip)' from wiki author field
$doc->author = preg_replace('/\(.*?\)/', '', $page['author']);
$doc->contents = $page['content'];
$doc->url = wiki_make_link($wiki_id, $page['pagename'], $page['version']);
$doc->author = $page['author'];
$doc->contents = $page['cachedcontent'];
$doc->url = wiki_make_link($page['id']);

// module specific information; optional
$data->version = $page['version'];
//$data->version = $page['version'];
$data->wiki = $wiki_id;

// construct the parent class
Expand All @@ -72,10 +72,10 @@ function wiki_name_convert($str) {
* @param int $version
* @uses $CFG
*/
function wiki_make_link($wikiId, $title, $version) {
function wiki_make_link($pageid) {
global $CFG;

return $CFG->wwwroot.'/mod/wiki/view.php?wid='.$wikiId.'&amp;page='.wiki_name_convert($title).'&amp;version='.$version;
return $CFG->wwwroot.'/mod/wiki/view.php?pageid='.$pageid;
}

/**
Expand All @@ -89,19 +89,21 @@ function wiki_make_link($wikiId, $title, $version) {
function wiki_get_latest_page(&$entry, $pagename, $version = 0) {
global $DB;

$pagename = $pagename;
$params = array('title' => $pagename, 'subwikiid' => $entry->id);

if ($version > 0 && is_int($version)) {
$versionclause = "AND ( version = :version )";
$sort = 'version DESC';
$params['version'] = $version;
} else {
$versionclause = '';
$sort = '';
}

$select = "( pagename = ':pagename' ) AND wiki = :wikiid $versionclause ";
$sort = 'version DESC';
$select = "( title = :title ) AND subwikiid = :subwikiid $versionclause ";

//change this to recordset_select, as per http://docs.moodle.org/en/Datalib_Notes
if ($result_arr = $DB->get_records_select('wiki_pages', $select, array('pagename' => $pagename, 'wikiid' => $entry->id, 'version' => $version), $sort, '*', 0, 1)) {
if ($result_arr = $DB->get_records_select('wiki_pages', $select, $params, $sort, '*', 0, 1)) {
foreach ($result_arr as $obj) {
$result_obj = $obj;
}
Expand Down Expand Up @@ -146,10 +148,10 @@ function wiki_get_latest_pages(&$entry) {
$pages = array();

//http://moodle.org/bugs/bug.php?op=show&bugid=5877&pos=0
if ($ids = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
if ($pagesets = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
if ($ids = $DB->get_records('wiki_pages', array('subwikiid' => $entry->id), '', 'distinct title')) {
if ($pagesets = $DB->get_records('wiki_pages', array('subwikiid' => $entry->id), '', 'distinct title')) {
foreach ($pagesets as $aPageset) {
$pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
$pages[] = wiki_get_latest_page($entry, $aPageset->title);
}
} else {
return false;
Expand Down Expand Up @@ -177,10 +179,11 @@ function wiki_iterator() {
* @return an array of searchable deocuments
*/
function wiki_get_content_for_index(&$wiki) {
global $DB;
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/wiki/locallib.php');

$documents = array();
$entries = wiki_get_entries($wiki);
$entries = wiki_get_subwikis($wiki->id);
if ($entries){
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
$cm = $DB->get_record('course_modules', array('course' => $wiki->course, 'module' => $coursemodule, 'instance' => $wiki->id));
Expand All @@ -194,8 +197,10 @@ function wiki_get_content_for_index(&$wiki) {
$pages = wiki_get_latest_pages($entry);
if (is_array($pages)) {
foreach($pages as $page) {
if (strlen($page->content) > 0) {
$documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id);
if (strlen($page->title) > 0) {
$owner = $DB->get_record('user', array('id' => $page->userid));
$page->author = fullname($owner);
$documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $wiki->course, $entry->groupid, $page->userid, $context->id);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions search/indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
* to the 'dbid' field in the index
* */

//this'll take some time, set up the environment
@set_time_limit(0);
@ob_implicit_flush(true);
@ob_end_flush();

/**
* includes and requires
*/
require_once('../config.php');
require_once($CFG->dirroot.'/search/lib.php');

//this'll take some time, set up the environment
@set_time_limit(0);
@ob_implicit_flush(true);
@ob_end_flush();

ini_set('include_path', $CFG->dirroot.DIRECTORY_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path'));

/// only administrators can index the moodle installation, because access to all pages is required
Expand Down Expand Up @@ -157,7 +158,11 @@
if ($documents){
foreach($documents as $document) {
$counter++;


// temporary fix until MDL-24822 is resolved
if ($document->group_id == -1 and $mod->name ='forum') {
$document->group_id = 0;
}
//object to insert into db
$dbid = $dbcontrol->addDocument($document);

Expand Down
1 change: 1 addition & 0 deletions search/indexersplash.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
$site = get_site();

$PAGE->set_url('/search/indexersplash.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->navbar->add($strsearch, new moodle_url('/search/index.php'));
$PAGE->navbar->add($strquery, new moodle_url('/search/stats.php'));
$PAGE->navbar->add(get_string('runindexer','search'));
Expand Down
3 changes: 2 additions & 1 deletion search/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
}

echo html_writer::table($admin_table);
echo $OUTPUT->spacer(array('height'=>20, 'br'=>true)); // should be done with CSS instead
$spacer = array('height'=>20, 'br'=>true);
echo $OUTPUT->spacer($spacer); // should be done with CSS instead
echo $OUTPUT->heading($solutionsstr);

unset($admin_table->data);
Expand Down

0 comments on commit 6cd2c7f

Please sign in to comment.