mirror of
https://github.com/moodle/moodle.git
synced 2025-05-03 14:58:42 +02:00
global search MDL-24892 fixes for updating the search index.
This commit is contained in:
parent
388025cbeb
commit
8dc68e3e7c
@ -236,8 +236,8 @@ function assignment_single_document($id, $itemtype) {
|
||||
return null;
|
||||
}
|
||||
} elseif ($itemtype == 'submission') {
|
||||
if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))){
|
||||
if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))){
|
||||
if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))) {
|
||||
if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
@ -274,7 +274,7 @@ function data_single_document($id, $itemtype) {
|
||||
$content = @$content.' '.$aField;
|
||||
}
|
||||
unset($recordMetaData);
|
||||
$recordMetaData = $DB->get_record('data_records', array('id' => $aRecordId));
|
||||
$recordMetaData = $DB->get_record('data_records', array('id' => $id));
|
||||
$recordMetaData->title = $first;
|
||||
$recordMetaData->content = $content;
|
||||
return new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
|
||||
|
@ -220,7 +220,7 @@ function wiki_single_document($id, $itemtype) {
|
||||
global $DB;
|
||||
|
||||
$page = $DB->get_record('wiki_pages', array('id' => $id));
|
||||
$entry = $DB->get_record('wiki_entries', array('id' => $page->wiki));
|
||||
$entry = $DB->get_record('wiki_entries', array('id' => $page->subwikiid));
|
||||
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
|
||||
$cm = $DB->get_record('course_modules', array('course' => $entry->course, 'module' => $coursemodule, 'instance' => $entry->wikiid));
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
@ -241,7 +241,7 @@ function wiki_delete($info, $itemtype) {
|
||||
//returns the var names needed to build a sql query for addition/deletions
|
||||
function wiki_db_names() {
|
||||
//[primary id], [table name], [time created field name], [time modified field name], [docsubtype], [additional where conditions for sql]
|
||||
return array(array('id', 'wiki_pages', 'timecreated', 'lastmodified', 'standard'));
|
||||
return array(array('id', 'wiki_pages', 'timecreated', 'timemodified', 'standard'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,7 +210,14 @@ require_once($CFG->dirroot.'/search/lib.php');
|
||||
/// mark the time we last updated
|
||||
|
||||
set_config('search_indexer_run_date', time());
|
||||
|
||||
|
||||
//mark last update times for mods to now.
|
||||
if ($mods = search_collect_searchables(false, true)){
|
||||
foreach($mods as $mod) {
|
||||
$indexdatestring = 'search_indexer_update_date_'.$mod->name;
|
||||
set_config($indexdatestring, time());
|
||||
}
|
||||
}
|
||||
/// and the index size
|
||||
|
||||
set_config('search_index_size', (int)$index->count());
|
||||
|
@ -56,8 +56,7 @@
|
||||
}
|
||||
$dbcontrol = new IndexDBControl();
|
||||
$update_count = 0;
|
||||
$indexdate = 0 + @$CFG->search_indexer_update_date;
|
||||
$startupdatedate = time();
|
||||
$mainstartupdatedate = time();
|
||||
|
||||
/// indexing changed resources
|
||||
|
||||
@ -66,6 +65,13 @@
|
||||
if ($mods = search_collect_searchables(false, true)){
|
||||
|
||||
foreach ($mods as $mod) {
|
||||
$indexdate = 0;
|
||||
$indexdatestring = 'search_indexer_update_date_'.$mod->name;
|
||||
$startupdatedate = time();
|
||||
if (isset($CFG->$indexdatestring)) {
|
||||
$indexdate = $CFG->$indexdatestring;
|
||||
}
|
||||
|
||||
$class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
|
||||
$get_document_function = $mod->name.'_single_document';
|
||||
$delete_function = $mod->name.'_delete';
|
||||
@ -81,8 +87,7 @@
|
||||
$valuesArray = $db_names_function();
|
||||
if ($valuesArray){
|
||||
foreach($valuesArray as $values){
|
||||
|
||||
$where = (!empty($values[5])) ? 'AND ('.$values[5].')' : '';
|
||||
$where = (isset($values[5]) and $values[5]!='') ? 'AND ('.$values[5].')' : '';
|
||||
$itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
|
||||
|
||||
//TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
|
||||
@ -97,8 +102,7 @@
|
||||
doctype = ?
|
||||
$itemtypes
|
||||
";
|
||||
$docIds = $DB->get_records_sql_menu($query, array($values[1]));
|
||||
|
||||
$docIds = $DB->get_records_sql_menu($query, array($mod->name));
|
||||
if (!empty($docIds)){
|
||||
list($usql, $params) = $DB->get_in_or_equal(array_keys($docIds));
|
||||
$query = "
|
||||
@ -121,11 +125,13 @@
|
||||
$updates[] = $delete_function($record->docid, $docIds[$record->docid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($updates as $update) {
|
||||
++$update_count;
|
||||
|
||||
//delete old document
|
||||
// change from default text only search to include numerals for this search.
|
||||
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
|
||||
$doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
|
||||
|
||||
//get the record, should only be one
|
||||
@ -140,7 +146,7 @@
|
||||
|
||||
//object to insert into db
|
||||
$dbid = $dbcontrol->addDocument($add);
|
||||
|
||||
|
||||
//synchronise db with index
|
||||
$add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
|
||||
mtrace(" Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
|
||||
@ -150,6 +156,12 @@
|
||||
else{
|
||||
mtrace("No types to update.\n");
|
||||
}
|
||||
//commit changes
|
||||
$index->commit();
|
||||
|
||||
//update index date
|
||||
set_config($indexdatestring, $startupdatedate);
|
||||
|
||||
mtrace("Finished $mod->name.\n");
|
||||
}
|
||||
}
|
||||
@ -158,10 +170,10 @@
|
||||
|
||||
//commit changes
|
||||
$index->commit();
|
||||
|
||||
|
||||
//update index date
|
||||
set_config('search_indexer_update_date', $startupdatedate);
|
||||
|
||||
set_config('search_indexer_update_date', $mainstartupdatedate);
|
||||
|
||||
mtrace("Finished $update_count updates");
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user