mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
global search MDL-24892 fixes for updating the search index.
This commit is contained in:
parent
388025cbeb
commit
8dc68e3e7c
5 changed files with 36 additions and 17 deletions
|
@ -274,7 +274,7 @@ function data_single_document($id, $itemtype) {
|
||||||
$content = @$content.' '.$aField;
|
$content = @$content.' '.$aField;
|
||||||
}
|
}
|
||||||
unset($recordMetaData);
|
unset($recordMetaData);
|
||||||
$recordMetaData = $DB->get_record('data_records', array('id' => $aRecordId));
|
$recordMetaData = $DB->get_record('data_records', array('id' => $id));
|
||||||
$recordMetaData->title = $first;
|
$recordMetaData->title = $first;
|
||||||
$recordMetaData->content = $content;
|
$recordMetaData->content = $content;
|
||||||
return new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
|
return new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
|
||||||
|
|
|
@ -220,7 +220,7 @@ function wiki_single_document($id, $itemtype) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$page = $DB->get_record('wiki_pages', array('id' => $id));
|
$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'));
|
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
|
||||||
$cm = $DB->get_record('course_modules', array('course' => $entry->course, 'module' => $coursemodule, 'instance' => $entry->wikiid));
|
$cm = $DB->get_record('course_modules', array('course' => $entry->course, 'module' => $coursemodule, 'instance' => $entry->wikiid));
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$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
|
//returns the var names needed to build a sql query for addition/deletions
|
||||||
function wiki_db_names() {
|
function wiki_db_names() {
|
||||||
//[primary id], [table name], [time created field name], [time modified field name], [docsubtype], [additional where conditions for sql]
|
//[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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -211,6 +211,13 @@ require_once($CFG->dirroot.'/search/lib.php');
|
||||||
|
|
||||||
set_config('search_indexer_run_date', time());
|
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
|
/// and the index size
|
||||||
|
|
||||||
set_config('search_index_size', (int)$index->count());
|
set_config('search_index_size', (int)$index->count());
|
||||||
|
|
|
@ -56,8 +56,7 @@
|
||||||
}
|
}
|
||||||
$dbcontrol = new IndexDBControl();
|
$dbcontrol = new IndexDBControl();
|
||||||
$update_count = 0;
|
$update_count = 0;
|
||||||
$indexdate = 0 + @$CFG->search_indexer_update_date;
|
$mainstartupdatedate = time();
|
||||||
$startupdatedate = time();
|
|
||||||
|
|
||||||
/// indexing changed resources
|
/// indexing changed resources
|
||||||
|
|
||||||
|
@ -66,6 +65,13 @@
|
||||||
if ($mods = search_collect_searchables(false, true)){
|
if ($mods = search_collect_searchables(false, true)){
|
||||||
|
|
||||||
foreach ($mods as $mod) {
|
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';
|
$class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
|
||||||
$get_document_function = $mod->name.'_single_document';
|
$get_document_function = $mod->name.'_single_document';
|
||||||
$delete_function = $mod->name.'_delete';
|
$delete_function = $mod->name.'_delete';
|
||||||
|
@ -81,8 +87,7 @@
|
||||||
$valuesArray = $db_names_function();
|
$valuesArray = $db_names_function();
|
||||||
if ($valuesArray){
|
if ($valuesArray){
|
||||||
foreach($valuesArray as $values){
|
foreach($valuesArray as $values){
|
||||||
|
$where = (isset($values[5]) and $values[5]!='') ? 'AND ('.$values[5].')' : '';
|
||||||
$where = (!empty($values[5])) ? 'AND ('.$values[5].')' : '';
|
|
||||||
$itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
|
$itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
|
||||||
|
|
||||||
//TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
|
//TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
|
||||||
|
@ -97,8 +102,7 @@
|
||||||
doctype = ?
|
doctype = ?
|
||||||
$itemtypes
|
$itemtypes
|
||||||
";
|
";
|
||||||
$docIds = $DB->get_records_sql_menu($query, array($values[1]));
|
$docIds = $DB->get_records_sql_menu($query, array($mod->name));
|
||||||
|
|
||||||
if (!empty($docIds)){
|
if (!empty($docIds)){
|
||||||
list($usql, $params) = $DB->get_in_or_equal(array_keys($docIds));
|
list($usql, $params) = $DB->get_in_or_equal(array_keys($docIds));
|
||||||
$query = "
|
$query = "
|
||||||
|
@ -126,6 +130,8 @@
|
||||||
++$update_count;
|
++$update_count;
|
||||||
|
|
||||||
//delete old document
|
//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}");
|
$doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
|
||||||
|
|
||||||
//get the record, should only be one
|
//get the record, should only be one
|
||||||
|
@ -150,6 +156,12 @@
|
||||||
else{
|
else{
|
||||||
mtrace("No types to update.\n");
|
mtrace("No types to update.\n");
|
||||||
}
|
}
|
||||||
|
//commit changes
|
||||||
|
$index->commit();
|
||||||
|
|
||||||
|
//update index date
|
||||||
|
set_config($indexdatestring, $startupdatedate);
|
||||||
|
|
||||||
mtrace("Finished $mod->name.\n");
|
mtrace("Finished $mod->name.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +172,7 @@
|
||||||
$index->commit();
|
$index->commit();
|
||||||
|
|
||||||
//update index date
|
//update index date
|
||||||
set_config('search_indexer_update_date', $startupdatedate);
|
set_config('search_indexer_update_date', $mainstartupdatedate);
|
||||||
|
|
||||||
mtrace("Finished $update_count updates");
|
mtrace("Finished $update_count updates");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue