Showing search settings status when trying to use the search module see #3166

skala
Julio Montoya 15 years ago
parent f4056bddda
commit bd1ab08d8c
  1. 46
      main/admin/settings.lib.php
  2. 78
      main/document/upload.php
  3. 8
      main/inc/lib/database.lib.php
  4. 2
      main/inc/lib/search/DokeosIndexer.class.php
  5. 4
      main/inc/lib/search/IndexableChunk.class.php
  6. 52
      main/inc/lib/search/search_widget.css
  7. 174
      main/inc/lib/search/search_widget.php
  8. 78
      main/inc/lib/search/tool_processors/document_processor.class.php
  9. 89
      main/inc/lib/search/tool_processors/learnpath_processor.class.php
  10. 107
      main/inc/lib/search/xapian/XapianIndexer.class.php
  11. 70
      main/inc/lib/search/xapian/XapianQuery.php
  12. 10
      main/inc/lib/sortabletable.class.php
  13. 44
      main/newscorm/lp_list_search.css
  14. 26
      main/newscorm/lp_list_search.php
  15. 2
      searchdb/readme.txt

@ -564,11 +564,10 @@ function handle_search() {
} }
$group = array(); $group = array();
$url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment')); $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment'));
if (empty($sf_values)) { if (empty($sf_values)) {
$form->addElement('html', get_lang('SearchPrefilterPrefix')); $form->addElement('html', get_lang('SearchPrefilterPrefix'));
} else { } else {
$form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, ''); $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
$default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix'); $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
} }
$form->addElement('html', $url); $form->addElement('html', $url);
@ -617,29 +616,56 @@ function handle_search() {
$dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok')); $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok'));
$specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); $specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok'));
//Testing specific fields
if (empty($specific_fields)) { if (empty($specific_fields)) {
$specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField')); $specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField'));
} }
//Testing xapian extension
if (!extension_loaded('xapian')) { if (!extension_loaded('xapian')) {
$xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error')); $xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error'));
} }
//Testing xapian searchdb path
if (!is_dir($xapian_path)) { if (!is_dir($xapian_path)) {
$dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error')); $dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error'));
} }
//Testing xapian searchdb path is writable
if (!is_writable($xapian_path)) { if (!is_writable($xapian_path)) {
$dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error')); $dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error'));
} }
$data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded); $data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded);
$data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists); $data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists);
$data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable); $data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable);
$data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists); $data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists);
echo Display::tag('h3', get_lang('Settings'));
$table = new SortableTableFromArray($data); $table = new SortableTableFromArray($data);
$table->set_header(0,get_lang('Setting'), false); $table->set_header(0, get_lang('Setting'), false);
$table->set_header(1,get_lang('Value'), false); $table->set_header(1, get_lang('Status'), false);
echo $table->display(); echo $table->display();
//@todo windows support
if (api_is_windows_os() == false) {
$list_of_programs = array('pdftotext','ps2pdf', 'catdoc','html2text','unrtf', 'catppt', 'xls2csv');
foreach($list_of_programs as $program) {
$output = null;
exec("which $program", $output, $ret_val);
$icon = Display::return_icon('bullet_red.gif', get_lang('NotInstalled'));
if (!empty($output[0])) {
$icon = Display::return_icon('bullet_green.gif', get_lang('Installed'));
}
$data2[]= array($program, $output[0], $icon);
}
echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles'));
$table = new SortableTableFromArray($data2);
$table->set_header(0, get_lang('Program'), false);
$table->set_header(1, get_lang('Path'), false);
$table->set_header(2, get_lang('Status'), false);
echo $table->display();
} else {
Display::display_warning_message(get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool'));
}
} }
} }

@ -191,60 +191,6 @@ if (!empty($_FILES)) {
DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $_POST['title'], $_POST['comment'], $_POST['unzip'], $_POST['if_exists'], $_POST['index_document'], true); DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $_POST['title'], $_POST['comment'], $_POST['unzip'], $_POST['if_exists'], $_POST['index_document'], true);
} }
// @todo remove this submit_image ???
/*
// Missing images are submitted
if (isset($_POST['submit_image'])) {
$number_of_uploaded_images = count($_FILES['img_file']['name']);
//if images are uploaded
if ($number_of_uploaded_images > 0) {
// We could also create a function for this, I'm not sure...
// Create a directory for the missing files
$img_directory = str_replace('.', '_', $_POST['related_file'].'_files');
$missing_files_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $img_directory);
// Put the uploaded files in the new directory and get the paths
$paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space);
// Open the html file and replace the paths
replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir.$_POST['related_file']);
// Update parent folders
item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
}
}
*/
//@todo keep it simple this page should only upload files!
/*
// They want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
$added_slash = ($path=='/') ? '' : '/';
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
$created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
if ($created_dir) {
Display::display_confirmation_message(get_lang('DirCr'), false);
$path = $created_dir;
} else {
display_error(get_lang('CannotCreateDir'));
}
}*/
// Tracking not needed here?
//event_access_tool(TOOL_DOCUMENT);
/* They want to create a new directory */
/*
if (isset($_GET['createdir'])) {
// create the form that asks for the directory name
$new_folder_text = '<form action="'.api_get_self().'" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
$new_folder_text .= get_lang('NewDir') .' ';
$new_folder_text .= '<input type="text" name="dirname"/>';
$new_folder_text .= '<button type="submit" class="save" name="create_dir">'.get_lang('CreateFolder').'</button>';
$new_folder_text .= '</form>';
// Show the form
//Display::display_normal_message($new_folder_text, false);
echo create_dir_form();
}*/
// Actions // Actions
echo '<div class="actions">'; echo '<div class="actions">';
@ -290,17 +236,17 @@ $form->addElement('checkbox', 'unzip', get_lang('Options'), get_lang('Uncompress
if (api_get_setting('search_enabled') == 'true') { if (api_get_setting('search_enabled') == 'true') {
//TODO: include language file //TODO: include language file
$supported_formats = 'Supported formats for index: Text plain, PDF, Postscript, MS Word, HTML, RTF, MS Power Point'; $supported_formats = get_lang('SupportedFormatsForIndex').': HTML, PDF, TXT, PDF, Postscript, MS Word, RTF, MS Power Point';
$form -> addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'<div style="font-size: 80%" >'.$supported_formats.'</div>'); $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'<div style="font-size: 80%" >'.$supported_formats.'</div>');
$form -> addElement('html', '<br /><div class="row">'); $form->addElement('html', '<br /><div class="row">');
$form -> addElement('html', '<div class="label">'.get_lang('SearchFeatureDocumentLanguage').'</div>'); $form->addElement('html', '<div class="label">'.get_lang('SearchFeatureDocumentLanguage').'</div>');
$form -> addElement('html', '<div class="formw">'.api_get_languages_combo().'</div>'); $form->addElement('html', '<div class="formw">'.api_get_languages_combo().'</div>');
$form -> addElement('html', '</div><div class="sub-form">'); $form->addElement('html', '</div><div class="sub-form">');
$specific_fields = get_specific_field_list(); $specific_fields = get_specific_field_list();
foreach ($specific_fields as $specific_field) { foreach ($specific_fields as $specific_field) {
$form -> addElement('text', $specific_field['code'], $specific_field['name'].' : '); $form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
} }
$form -> addElement('html', '</div>'); $form->addElement('html', '</div>');
} }
$form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing'); $form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing');
@ -320,9 +266,7 @@ $form->setDefaults($defaults);
$simple_form = $form->return_form(); $simple_form = $form->return_form();
echo ' echo '<style>
<style>
.files { .files {
border-collapse: collapse; border-collapse: collapse;
margin-top: 10px; margin-top: 10px;
@ -331,9 +275,7 @@ echo '
.files td { .files td {
padding: 3px 10px 3px 0; padding: 3px 10px 3px 0;
} }
</style>';
</style>
';
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php'; $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php';
$multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'<br />'; $multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'<br />';
$multiple_form .= '<form id="file_upload" action="'.$url.'" method="POST" enctype="multipart/form-data"> $multiple_form .= '<form id="file_upload" action="'.$url.'" method="POST" enctype="multipart/form-data">

@ -441,17 +441,19 @@ class Database {
* *
* @param string $course_code * @param string $course_code
* @param string $table the name of the table * @param string $table the name of the table
* @todo this function should be deprecated use api_get_course_info() and then get_course_table()
*/ */
public static function get_course_table_from_code($course_code, $table) { public static function get_course_table_from_code($course_code, $table) {
$course_table = self::get_main_table(TABLE_MAIN_COURSE); $course_table = self::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = self::get_main_table(TABLE_MAIN_CATEGORY); $course_cat_table = self::get_main_table(TABLE_MAIN_CATEGORY);
$result = self::fetch_array(self::query( $sql = "SELECT $course_table.db_name, $course_cat_table.code
"SELECT $course_table.db_name, $course_cat_table.code
FROM $course_table FROM $course_table
LEFT JOIN $course_cat_table LEFT JOIN $course_cat_table
ON $course_table.category_code = $course_cat_table.code ON $course_table.category_code = $course_cat_table.code
WHERE $course_table.code = '$course_code' WHERE $course_table.code = '$course_code'
LIMIT 1")); LIMIT 1";
$result = self::fetch_array(self::query($sql));
return sprintf("%s.%s", $result[0], $table); return sprintf("%s.%s", $result[0], $table);
} }

@ -1,4 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */
require_once dirname(__FILE__) . '/../../global.inc.php'; require_once dirname(__FILE__) . '/../../global.inc.php';
include_once 'xapian/XapianIndexer.class.php'; include_once 'xapian/XapianIndexer.class.php';

@ -1,4 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */
// some constants to avoid serialize string keys on serialized data array // some constants to avoid serialize string keys on serialized data array
define('SE_COURSE_ID', 0); define('SE_COURSE_ID', 0);
define('SE_TOOL_ID', 1); define('SE_TOOL_ID', 1);
@ -11,7 +13,7 @@ define('SE_DOCTYPE_EXERCISE_QUESTION', 1);
// xapian prefixes // xapian prefixes
define('XAPIAN_PREFIX_COURSEID','C'); define('XAPIAN_PREFIX_COURSEID','C');
define('XAPIAN_PREFIX_TOOLID','O'); define('XAPIAN_PREFIX_TOOLID', 'O');
abstract class _IndexableChunk abstract class _IndexableChunk
{ {

@ -15,8 +15,8 @@
#submit { #submit {
background-image: url('/main/img/search-lense.gif'); background-image: url('/main/img/search-lense.gif');
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: 0px -1px; background-position: 0px 3px;
padding-left:18px; padding-left:28px;
} }
.lower-submit { .lower-submit {
float:right; float:right;
@ -40,3 +40,51 @@
#operator-select { #operator-select {
padding-right: 0.9em; padding-right: 0.9em;
} }
.doc_table {
width: 30%;
text-align: left;
}
.doc_img {
border: 1px solid black;
padding: 1px solid white;
background: white;
}
.doc_img,
.doc_img img {
width: 120px;
}
.doc_text,
.doc_title {
padding-left: 10px;
vertical-align: top;
}
.doc_title {
font-size: large;
font-weight: bold;
height: 2em;
}
.data_table {
text-align:center;
}
.cls {
clear:both
}
#search-results-container {
width: 940px;
border: 1px solid #979797;
position: relative;
background-image: url('/main/img/search_background_bar.jpg');
background-repeat: repeat-x
}
#mode-selector {
width: 100px;
padding: 4px;
top: 0px;
z-index: 9;
float:left;
height:15px;
}

@ -139,39 +139,41 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) {
<input type="hidden" name="type" value="'. $type .'"/> <input type="hidden" name="type" value="'. $type .'"/>
<input type="hidden" name="tablename_page_nr" value="1" /> <input type="hidden" name="tablename_page_nr" value="1" />
'.$submit_button1.' '.$submit_button1.'
<br /><br /> <br /><br />';
<span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span> $list = get_specific_field_list();
if(!empty($list)) {
$form = '<span class="search-links-box">'. $advanced_options .'&nbsp;</span>
<div id="tags" class="tags" style="display:'. $display_thesaurus .';"> <div id="tags" class="tags" style="display:'. $display_thesaurus .';">
<div class="search-help-box">'. $help .'</div> <div class="search-help-box">'. $help .'</div>
<table> <table>
<tr> <tr>';
'; $form .= format_specific_fields_selects($sf_terms, $op);
$form .= format_specific_fields_selects($sf_terms, $op); $or_checked = '';
$or_checked = ''; $and_checked = '';
$and_checked = ''; if ($op == 'or') {
if ($op == 'or') { $or_checked = 'checked="checked"';
$or_checked = 'checked="checked"'; } else if ($op == 'and') {
} else if ($op == 'and') { $and_checked = 'checked="checked"';
$and_checked = 'checked="checked"'; }
$form .= '
</tr>
<tr>
<td id="operator-select">
'. get_lang('SearchCombineSearchWith') .':<br />
<input type="radio" class="search-operator" name="operator" value="or" '. $or_checked .'>'. api_strtoupper(get_lang('Or')) .'</input>
<input type="radio" class="search-operator" name="operator" value="and" '. $and_checked .'>'. api_strtoupper(get_lang('And')) .'</input>
</td>
<td></td>
<td>
<br />
'.$reset_button.'
'. $submit_button2.'
</td>
</tr>
</table>
</div>';
} }
$form .= ' $form .='</form>
</tr>
<tr>
<td id="operator-select">
'. get_lang('SearchCombineSearchWith') .':<br />
<input type="radio" class="search-operator" name="operator" value="or" '. $or_checked .'>'. api_strtoupper(get_lang('Or')) .'</input>
<input type="radio" class="search-operator" name="operator" value="and" '. $and_checked .'>'. api_strtoupper(get_lang('And')) .'</input>
</td>
<td></td>
<td>
<br />
'.$reset_button.'
'. $submit_button2.'
</td>
</tr>
</table>
</div>
</form>
<br style="clear: both;"/> <br style="clear: both;"/>
'; ';
return $form; return $form;
@ -198,6 +200,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
if (isset($_GET['action']) && strcmp(trim($_GET['action']),'search')===0) { if (isset($_GET['action']) && strcmp(trim($_GET['action']),'search')===0) {
$action='index.php'; $action='index.php';
} }
$form = ' $form = '
<form id="dokeos_search" action="'. $action .'" method="GET"> <form id="dokeos_search" action="'. $action .'" method="GET">
<input type="text" id="query" name="query" size="40" /> <input type="text" id="query" name="query" size="40" />
@ -205,61 +208,66 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
<input type="hidden" name="type" value="'. $type .'"/> <input type="hidden" name="type" value="'. $type .'"/>
<input type="hidden" name="tablename_page_nr" value="1" /> <input type="hidden" name="tablename_page_nr" value="1" />
<input type="submit" id="submit" value="'. get_lang("Search") .'" /> <input type="submit" id="submit" value="'. get_lang("Search") .'" />
<br /><br /> <br /><br />';
<span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span> $list = get_specific_field_list();
<div id="tags" class="tags" style="display:'. $display_thesaurus .';"> if(!empty($list)) {
<div class="search-help-box">'. $help .'</div> $form .=' <span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span>
<table> <div id="tags" class="tags" style="display:'. $display_thesaurus .';">
<tr>'; <div class="search-help-box">'. $help .'</div>
<table>
if (!is_null($prefilter_prefix)) { <tr>';
//sorting the array of terms if (!is_null($prefilter_prefix)) {
$temp = array(); //sorting the array of terms
foreach ($sf_terms[$prefilter_prefix] as $key => $value) { $temp = array();
$temp[trim(stripslashes($value['name']))] = $key; foreach ($sf_terms[$prefilter_prefix] as $key => $value) {
} $temp[trim(stripslashes($value['name']))] = $key;
$temp = array_flip($temp); }
unset($sf_term_array); $temp = array_flip($temp);
natcasesort($temp); unset($sf_term_array);
$sf_term_array = $temp; natcasesort($temp);
$sf_term_array = $temp;
// get specific field name
$sf_value = get_specific_field_list(array( 'code' => "'$prefilter_prefix'" )); // get specific field name
$sf_value = array_shift($sf_value); $sf_value = get_specific_field_list(array( 'code' => "'$prefilter_prefix'" ));
$form .= '<label class="sf-select-multiple-title" for="sf_'. $prefix .'[]">'.$icons_for_search_terms[$prefix].' '.$sf_value['name'].'</label><br />'; $sf_value = array_shift($sf_value);
$form .= '<label class="sf-select-multiple-title" for="sf_'. $prefix .'[]">'.$icons_for_search_terms[$prefix].' '.$sf_value['name'].'</label><br />';
$form .= format_one_specific_field_select($prefilter_prefix, $sf_term_array, $op, 'id="prefilter"');
$form .= format_specific_fields_selects($sf_terms, $op, $prefilter_prefix); $form .= format_one_specific_field_select($prefilter_prefix, $sf_term_array, $op, 'id="prefilter"');
} else { $form .= format_specific_fields_selects($sf_terms, $op, $prefilter_prefix);
$form .= format_specific_fields_selects($sf_terms, $op); } else {
} $form .= format_specific_fields_selects($sf_terms, $op);
$or_checked = ''; }
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"'; $or_checked = '';
} else if ($op == 'and') { $and_checked = '';
$and_checked = 'checked="checked"'; if ($op == 'or') {
} $or_checked = 'checked="checked"';
$form .= ' } else if ($op == 'and') {
</tr> $and_checked = 'checked="checked"';
<tr> }
<td id="operator-select"> $form .= '
'. get_lang('SearchCombineSearchWith') .':<br /> </tr>
<input type="radio" class="search-operator" name="operator" value="or" '. $or_checked .'>'. api_strtoupper(get_lang('Or')) .'</input> <tr>
<input type="radio" class="search-operator" name="operator" value="and" '. $and_checked .'>'. api_strtoupper(get_lang('And')) .'</input> <td id="operator-select">
</td> '. get_lang('SearchCombineSearchWith') .':<br />
<td></td> <input type="radio" class="search-operator" name="operator" value="or" '. $or_checked .'>'. api_strtoupper(get_lang('Or')) .'</input>
<td> <input type="radio" class="search-operator" name="operator" value="and" '. $and_checked .'>'. api_strtoupper(get_lang('And')) .'</input>
<br /> </td>
<input class="lower-submit" type="submit" value="'. get_lang('Search') .'" /> <td></td>
<input type="submit" id="tags-clean" value="'. get_lang('SearchResetKeywords') .'" /> <td>
</td> <br />
</tr> <input class="lower-submit" type="submit" value="'. get_lang('Search') .'" />
</table> <input type="submit" id="tags-clean" value="'. get_lang('SearchResetKeywords') .'" />
</div> </td>
</tr>
</table>
</div>';
}
$form .= '
</form> </form>
<br style="clear: both;"/> <br style="clear: both;"/>';
';
return $form; return $form;
} }

@ -58,42 +58,46 @@ class document_processor extends search_processor {
* Get document information * Get document information
*/ */
private function get_information($course_id, $doc_id) { private function get_information($course_id, $doc_id) {
$doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT); $course_information = api_get_course_info($course_id);
$item_property_table = Database::get_course_table_from_code($course_id, TABLE_ITEM_PROPERTY); if (!empty($course_information)) {
$doc_id = Database::escape_string($doc_id); $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_information['db_name']);
$sql = "SELECT * $doc_table = Database::get_course_table(TABLE_DOCUMENT, $course_information['db_name']);
FROM $doc_table
WHERE $doc_table.id = $doc_id $doc_id = Database::escape_string($doc_id);
LIMIT 1"; $sql = "SELECT *
$dk_result = Database::query ($sql); FROM $doc_table
WHERE $doc_table.id = $doc_id
$sql = "SELECT insert_user_id LIMIT 1";
FROM $item_property_table $dk_result = Database::query ($sql);
WHERE ref = $doc_id
AND tool = '". TOOL_DOCUMENT ."' $sql = "SELECT insert_user_id
LIMIT 1"; FROM $item_property_table
WHERE ref = $doc_id
$name = ''; AND tool = '". TOOL_DOCUMENT ."'
if ($row = Database::fetch_array ($dk_result)) { LIMIT 1";
$name = $row['title'];
$url = api_get_path(WEB_PATH) . 'courses/%s/document%s'; $name = '';
$url = sprintf($url, api_get_course_path($course_id), $row['path']); if ($row = Database::fetch_array ($dk_result)) {
// Get the image path $name = $row['title'];
include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php'; $url = api_get_path(WEB_PATH) . 'courses/%s/document%s';
$icon = choose_image(basename($row['path'])); $url = sprintf($url, api_get_course_path($course_id), $row['path']);
$thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon; // Get the image path
$image = $thumbnail; include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php';
//FIXME: use big images $icon = choose_image(basename($row['path']));
// get author $thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon;
$author = ''; $image = $thumbnail;
$item_result = Database::query ($sql); //FIXME: use big images
if ($row = Database::fetch_array ($item_result)) { // get author
$user_data = api_get_user_info($row['insert_user_id']); $author = '';
$author = api_get_person_name($user_data['firstName'], $user_data['lastName']); $item_result = Database::query ($sql);
} if ($row = Database::fetch_array ($item_result)) {
$user_data = api_get_user_info($row['insert_user_id']);
$author = api_get_person_name($user_data['firstName'], $user_data['lastName']);
}
}
return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here?
} else {
return array();
} }
return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here?
} }
} }
?>

@ -78,50 +78,55 @@ class learnpath_processor extends search_processor {
* Get learning path information * Get learning path information
*/ */
private function get_information($course_id, $lp_id, $has_document_id=TRUE) { private function get_information($course_id, $lp_id, $has_document_id=TRUE) {
$lpi_table = Database::get_course_table_from_code($course_id, TABLE_LP_ITEM);
$lp_table = Database::get_course_table_from_code($course_id, TABLE_LP_MAIN); $course_information = api_get_course_info($course_id);
$doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT); if (!empty($course_information)) {
$lp_id = Database::escape_string($lp_id); $lpi_table = Database::get_course_table(TABLE_LP_ITEM, $course_information['db_name']);
$lp_table = Database::get_course_table_from_code(TABLE_LP_MAIN, $course_information['db_name']);
$doc_table = Database::get_course_table_from_code(TABLE_DOCUMENT, $course_information['db_name']);
$lp_id = Database::escape_string($lp_id);
if ($has_document_id) { if ($has_document_id) {
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path
FROM $lp_table, $lpi_table FROM $lp_table, $lpi_table
INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id
WHERE $lpi_table.lp_id = $lp_id WHERE $lpi_table.lp_id = $lp_id
AND $lpi_table.display_order = 1 AND $lpi_table.display_order = 1
AND $lp_table.id = $lpi_table.lp_id AND $lp_table.id = $lpi_table.lp_id
LIMIT 1"; LIMIT 1";
}
else {
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author
FROM $lp_table, $lpi_table
WHERE $lpi_table.lp_id = $lp_id
AND $lpi_table.display_order = 1
AND $lp_table.id = $lpi_table.lp_id
LIMIT 1";
}
$dk_result = Database::query ($sql);
$path = '';
$name = '';
if ($row = Database::fetch_array ($dk_result)) {
// Get the image path
$img_location = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_id)."/document/";
$thumbnail_path = str_replace ('.png.html', '_thumb.png', $row['path']);
$big_img_path = str_replace ('.png.html', '.png', $row['path']);
$thumbnail = '';
if (!empty($thumbnail_path)) {
$thumbnail = $img_location . $thumbnail_path;
} }
$image = ''; else {
if (!empty($big_img_path)) { $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author
$image = $img_location . $big_img_path; FROM $lp_table, $lpi_table
WHERE $lpi_table.lp_id = $lp_id
AND $lpi_table.display_order = 1
AND $lp_table.id = $lpi_table.lp_id
LIMIT 1";
} }
$name = $row['name'];
$dk_result = Database::query ($sql);
$path = '';
$name = '';
if ($row = Database::fetch_array ($dk_result)) {
// Get the image path
$img_location = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_id)."/document/";
$thumbnail_path = str_replace ('.png.html', '_thumb.png', $row['path']);
$big_img_path = str_replace ('.png.html', '.png', $row['path']);
$thumbnail = '';
if (!empty($thumbnail_path)) {
$thumbnail = $img_location . $thumbnail_path;
}
$image = '';
if (!empty($big_img_path)) {
$image = $img_location . $big_img_path;
}
$name = $row['name'];
}
return array($thumbnail, $image, $name, $row['author']);
} else {
return array();
} }
return array($thumbnail, $image, $name, $row['author']);
} }
} }
?>

@ -1,4 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */
require_once 'xapian.php'; require_once 'xapian.php';
require_once dirname(__FILE__) . '/../IndexableChunk.class.php'; require_once dirname(__FILE__) . '/../IndexableChunk.class.php';
@ -59,21 +61,19 @@ abstract class XapianIndexer {
$path = api_get_path(SYS_PATH).'searchdb/'; $path = api_get_path(SYS_PATH).'searchdb/';
try { try {
$this->db = new XapianWritableDatabase($path, $dbMode); $this->db = new XapianWritableDatabase($path, $dbMode);
$this->indexer = new XapianTermGenerator(); $this->indexer = new XapianTermGenerator();
if (!in_array($lang, $this->xapian_languages())) {
$lang = 'english';
}
$this->stemmer = new XapianStem($lang); if (!in_array($lang, $this->xapian_languages())) {
$this->indexer->set_stemmer($this->stemmer); $lang = 'english';
}
return $this->db; $this->stemmer = new XapianStem($lang);
} $this->indexer->set_stemmer($this->stemmer);
catch (Exception $e) {
Display::display_error_message($e->getMessage()); return $this->db;
return 1; } catch (Exception $e) {
Display::display_error_message($e->getMessage());
return 1;
} }
} }
@ -100,39 +100,37 @@ abstract class XapianIndexer {
* @return integer New Xapian document ID or NULL upon failure * @return integer New Xapian document ID or NULL upon failure
*/ */
function index() { function index() {
try { try {
if (!empty($this->chunks)) { if (!empty($this->chunks)) {
foreach ($this->chunks as $chunk) { foreach ($this->chunks as $chunk) {
$doc = new XapianDocument(); $doc = new XapianDocument();
$this->indexer->set_document($doc); $this->indexer->set_document($doc);
if (!empty($chunk->terms)) { if (!empty($chunk->terms)) {
foreach ($chunk->terms as $term) { foreach ($chunk->terms as $term) {
/* FIXME: think of getting weight */ /* FIXME: think of getting weight */
$doc->add_term($term['flag'] . $term['name'], 1); $doc->add_term($term['flag'] . $term['name'], 1);
}
} }
// free-form index all data array (title, content, etc)
if (!empty($chunk->data)) {
foreach ($chunk->data as $key => $value) {
$this->indexer->index_text($value, 1);
}
}
$doc->set_data($chunk->xapian_data, 1);
$did = $this->db->add_document($doc);
//write to disk
$this->db->flush();
return $did;
} }
// free-form index all data array (title, content, etc)
if (!empty($chunk->data)) {
foreach ($chunk->data as $key => $value) {
$this->indexer->index_text($value, 1);
}
}
$doc->set_data($chunk->xapian_data, 1);
$did = $this->db->add_document($doc);
//write to disk
$this->db->flush();
return $did;
} }
} catch (Exception $e) {
Display::display_error_message($e->getMessage());
exit(1);
} }
}
catch (Exception $e) {
Display::display_error_message($e->getMessage());
exit(1);
}
} }
/** /**
@ -204,16 +202,16 @@ abstract class XapianIndexer {
* @param int did Xapian::docid * @param int did Xapian::docid
*/ */
function remove_document($did) { function remove_document($did) {
if ($this->db == NULL) { if ($this->db == NULL) {
$this->connectDb(); $this->connectDb();
} }
if (is_numeric($did) && $did>0) { if (is_numeric($did) && $did>0) {
$doc = $this->get_document($did); $doc = $this->get_document($did);
if ($doc !== FALSE) { if ($doc !== FALSE) {
$this->db->delete_document($did); $this->db->delete_document($did);
$this->db->flush(); $this->db->flush();
} }
} }
} }
/** /**
@ -294,5 +292,4 @@ abstract class XapianIndexer {
unset($this->db); unset($this->db);
unset($this->stemmer); unset($this->stemmer);
} }
} }
?>

@ -27,16 +27,17 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
try { try {
if (!is_object($db)) { if (!is_object($db)) {
$db = new XapianDatabase(XAPIAN_DB); $db = new XapianDatabase(XAPIAN_DB);
} }
// Build subqueries from $extra array. Now only used by tags search filter on search widget // Build subqueries from $extra array. Now only used by tags search filter on search widget
$subqueries = array(); $subqueries = array();
foreach ($extra as $subquery) { foreach ($extra as $subquery) {
if (!empty($subquery)) { if (!empty($subquery)) {
$subqueries[] = new XapianQuery($subquery); $subqueries[] = new XapianQuery($subquery);
} }
} }
$query = NULL; $query = NULL;
$enquire = new XapianEnquire($db); $enquire = new XapianEnquire($db);
@ -49,42 +50,52 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
$query_parser->set_database($db); $query_parser->set_database($db);
$query_parser->set_stemming_strategy(XapianQueryParser::STEM_SOME); $query_parser->set_stemming_strategy(XapianQueryParser::STEM_SOME);
$query_parser->add_boolean_prefix('courseid', XAPIAN_PREFIX_COURSEID); $query_parser->add_boolean_prefix('courseid', XAPIAN_PREFIX_COURSEID);
$query_parser->add_boolean_prefix('toolid', XAPIAN_PREFIX_TOOLID); $query_parser->add_boolean_prefix('toolid', XAPIAN_PREFIX_TOOLID);
$query = $query_parser->parse_query($query_string); $query = $query_parser->parse_query($query_string);
$query = new XapianQuery(XapianQuery::OP_AND, array_merge($subqueries, array($query))); $final_array = array_merge($subqueries, array($query));
} $query = new XapianQuery(XapianQuery::OP_AND, $final_array);
else { } else {
$query = new XapianQuery(XapianQuery::OP_OR, $subqueries); $query = new XapianQuery(XapianQuery::OP_OR, $subqueries);
} }
$enquire->set_query($query); $enquire->set_query($query);
$matches = $enquire->get_mset((int)$start, (int)$length); $matches = $enquire->get_mset((int)$start, (int)$length);
$specific_fields = get_specific_field_list(); $specific_fields = get_specific_field_list();
$results = array(); $results = array();
$i = $matches->begin(); $i = $matches->begin();
// Display the results.
//echo $matches->get_matches_estimated().'results found';
$count = 0; $count = 0;
while (!$i->equals($matches->end())) {
$count++; while (!$i->equals($matches->end())) {
$document = $i->get_document(); $count++;
if (is_object($document)) { $document = $i->get_document();
// process one item terms
$courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID); if (is_object($document)) {
$results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1); // process one item terms
$toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID); $courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID);
$results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1); $results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1);
$toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID);
// process each specific field prefix $results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1);
foreach ($specific_fields as $specific_field) {
$results[$count]['sf-'.$specific_field['code']] = xapian_get_doc_terms($document, $specific_field['code']); // process each specific field prefix
} foreach ($specific_fields as $specific_field) {
$results[$count]['sf-'.$specific_field['code']] = xapian_get_doc_terms($document, $specific_field['code']);
// rest of data }
$results[$count]['xapian_data'] = unserialize($document->get_data());
$results[$count]['score'] = ($i->get_percent()); // rest of data
} $results[$count]['xapian_data'] = unserialize($document->get_data());
$i->next(); $results[$count]['score'] = ($i->get_percent());
}
$i->next();
} }
switch ($count_type) { switch ($count_type) {
@ -101,7 +112,6 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
$count = $matches->get_matches_estimated(); $count = $matches->get_matches_estimated();
break; break;
} }
return array($count, $results); return array($count, $results);
} catch (Exception $e) { } catch (Exception $e) {
display_xapian_error($e->getMessage()); display_xapian_error($e->getMessage());

@ -158,9 +158,9 @@ class SortableTable extends HTML_Table {
$this->total_number_of_items = -1; $this->total_number_of_items = -1;
$this->get_total_number_function = $get_total_number_function; $this->get_total_number_function = $get_total_number_function;
$this->get_data_function = $get_data_function; $this->get_data_function = $get_data_function;
$this->column_filters = array (); $this->column_filters = array();
$this->form_actions = array (); $this->form_actions = array();
$this->checkbox_name = null; $this->checkbox_name = null;
$this->td_attributes = array (); $this->td_attributes = array ();
$this->th_attributes = array (); $this->th_attributes = array ();
$this->other_tables = array(); $this->other_tables = array();
@ -838,7 +838,7 @@ class SortableTableFromArray extends SortableTable {
* @param int $default_column * @param int $default_column
* @param int $default_items_per_page * @param int $default_items_per_page
*/ */
public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename') { public function __construct($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename') {
parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page); parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page);
$this->table_data = $table_data; $this->table_data = $table_data;
} }
@ -847,7 +847,7 @@ class SortableTableFromArray extends SortableTable {
* Get table data to show on current page * Get table data to show on current page
* @see SortableTable#get_table_data * @see SortableTable#get_table_data
*/ */
public function get_table_data ($from = 1, $sort = true) { public function get_table_data($from = 1, $sort = true) {
if ($sort) { if ($sort) {
$content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC); $content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
} else { } else {

@ -1,43 +1 @@
.doc_table { /* css styles moved to search_widget.css */
width: 30%;
text-align: left;
}
.doc_img {
border: 1px solid black;
padding: 1px solid white;
background: white;
}
.doc_img,
.doc_img img {
width: 120px;
}
.doc_text,
.doc_title {
padding-left: 10px;
vertical-align: top;
}
.doc_title {
font-size: large;
font-weight: bold;
height: 2em;
}
.data_table {
text-align:center;
}
.cls {
clear:both
}
#search-results-container {
width: 940px;
border: 1px solid #979797;
position: relative;
background-image: url(\'../img/search_background_bar.jpg\');
background-repeat: repeat-x
}
#mode-selector {
width: 100px;
padding: 4px;
position: absolute;
top: 0px;
z-index: 9;
}

@ -76,31 +76,43 @@ foreach ($specific_fields as $specific_field) {
} }
} }
} }
} else {
$sf_terms_for_code = xapian_get_all_terms(1000, $specific_field['code']);
foreach ($sf_terms_for_code as $term) {
if (!empty($term)) {
$term_array[] = dokeos_get_boolean_query($term['name']); // Here name includes prefix.
}
}
} }
} }
// Get right group of terms to show on multiple select. // Get right group of terms to show on multiple select.
$fixed_queries = array(); $fixed_queries = array();
$course_filter = NULL; $course_filter = NULL;
if ( ($cid=api_get_course_id()) != -1 ) { if ( ($cid=api_get_course_id()) != -1 ) {
// Results only from actual course. // Results only from actual course.
$course_filter = dokeos_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); $course_filter = dokeos_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid);
} }
if (count($term_array)) {
if (count($term_array)) {
$fixed_queries = dokeos_join_queries($term_array, null, $op); $fixed_queries = dokeos_join_queries($term_array, null, $op);
if ($course_filter != NULL) { if ($course_filter != NULL) {
$fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and'); $fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and');
} }
} else { } else {
if (!empty($query)) { if (!empty($query)) {
$fixed_queries = array($course_filter); $fixed_queries = array($course_filter);
} }
} }
//var_dump($fixed_queries);
list($count, $results) = dokeos_query_query(api_convert_encoding($query, 'UTF-8', $charset), 0, 1000, $fixed_queries); list($count, $results) = dokeos_query_query(api_convert_encoding($query, 'UTF-8', $charset), 0, 1000, $fixed_queries);
// Prepare blocks to show. // Prepare blocks to show.
$blocks = array(); $blocks = array();
if ($count > 0) { if ($count > 0) {
foreach ($results as $result) { foreach ($results as $result) {
// Fill the result array. // Fill the result array.
@ -122,10 +134,8 @@ if ($count > 0) {
$a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'], $a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'],
); );
} else { } else {
$title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? $result['author'] : '').'<div>'; $title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? ' '.$result['author'] : '').'<div>';
$blocks[] = array( $blocks[] = array($title);
$title,
);
} }
} }
} }
@ -158,7 +168,7 @@ if (count($blocks) > 0) {
$s->additional_parameters = $additional_parameters; $s->additional_parameters = $additional_parameters;
if ($mode == 'default') { if ($mode == 'default') {
$s->set_header(0, get_lang(ucfirst(TOOL_SEARCH))); $s->set_header(0, get_lang(ucfirst(TOOL_SEARCH)), false);
} }
$search_link = '<a href="%ssearch/index.php?mode=%s&action=search&query=%s%s">'; $search_link = '<a href="%ssearch/index.php?mode=%s&action=search&query=%s%s">';

@ -1,2 +0,0 @@
This directory is a placeholder for the search plugin, which allows the
indexation of Chamilo contents through the use of the Xapian search engine.
Loading…
Cancel
Save