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

skala
Julio Montoya 14 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();
$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'));
} 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');
}
$form->addElement('html', $url);
@ -617,29 +616,56 @@ function handle_search() {
$dir_is_writable = 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)) {
$specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField'));
}
//Testing xapian extension
if (!extension_loaded('xapian')) {
$xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error'));
}
//Testing xapian searchdb path
if (!is_dir($xapian_path)) {
$dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error'));
}
//Testing xapian searchdb path is writable
if (!is_writable($xapian_path)) {
$dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error'));
}
$data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded);
$data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists);
$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->set_header(0,get_lang('Setting'), false);
$table->set_header(1,get_lang('Value'), false);
echo $table->display();
$table->set_header(0, get_lang('Setting'), false);
$table->set_header(1, get_lang('Status'), false);
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);
}
// @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
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') {
//TODO: include language file
$supported_formats = 'Supported formats for index: Text plain, PDF, Postscript, MS Word, HTML, RTF, MS Power Point';
$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', '<div class="label">'.get_lang('SearchFeatureDocumentLanguage').'</div>');
$form -> addElement('html', '<div class="formw">'.api_get_languages_combo().'</div>');
$form -> addElement('html', '</div><div class="sub-form">');
$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('html', '<br /><div class="row">');
$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><div class="sub-form">');
$specific_fields = get_specific_field_list();
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');
@ -320,9 +266,7 @@ $form->setDefaults($defaults);
$simple_form = $form->return_form();
echo '
<style>
echo '<style>
.files {
border-collapse: collapse;
margin-top: 10px;
@ -331,9 +275,7 @@ echo '
.files td {
padding: 3px 10px 3px 0;
}
</style>
';
</style>';
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php';
$multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'<br />';
$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 $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) {
$course_table = self::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = self::get_main_table(TABLE_MAIN_CATEGORY);
$result = self::fetch_array(self::query(
"SELECT $course_table.db_name, $course_cat_table.code
$sql = "SELECT $course_table.db_name, $course_cat_table.code
FROM $course_table
LEFT JOIN $course_cat_table
ON $course_table.category_code = $course_cat_table.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);
}

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

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

@ -15,8 +15,8 @@
#submit {
background-image: url('/main/img/search-lense.gif');
background-repeat: no-repeat;
background-position: 0px -1px;
padding-left:18px;
background-position: 0px 3px;
padding-left:28px;
}
.lower-submit {
float:right;
@ -40,3 +40,51 @@
#operator-select {
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="tablename_page_nr" value="1" />
'.$submit_button1.'
<br /><br />
<span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span>
<br /><br />';
$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 class="search-help-box">'. $help .'</div>
<table>
<tr>
';
$form .= format_specific_fields_selects($sf_terms, $op);
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"';
} else if ($op == 'and') {
$and_checked = 'checked="checked"';
<tr>';
$form .= format_specific_fields_selects($sf_terms, $op);
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"';
} else if ($op == 'and') {
$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 .= '
</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>
<br style="clear: both;"/>
';
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) {
$action='index.php';
}
$form = '
<form id="dokeos_search" action="'. $action .'" method="GET">
<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="tablename_page_nr" value="1" />
<input type="submit" id="submit" value="'. get_lang("Search") .'" />
<br /><br />
<span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span>
<div id="tags" class="tags" style="display:'. $display_thesaurus .';">
<div class="search-help-box">'. $help .'</div>
<table>
<tr>';
if (!is_null($prefilter_prefix)) {
//sorting the array of terms
$temp = array();
foreach ($sf_terms[$prefilter_prefix] as $key => $value) {
$temp[trim(stripslashes($value['name']))] = $key;
}
$temp = array_flip($temp);
unset($sf_term_array);
natcasesort($temp);
$sf_term_array = $temp;
// get specific field name
$sf_value = get_specific_field_list(array( 'code' => "'$prefilter_prefix'" ));
$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);
} else {
$form .= format_specific_fields_selects($sf_terms, $op);
}
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"';
} else if ($op == 'and') {
$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 />
<input class="lower-submit" type="submit" value="'. get_lang('Search') .'" />
<input type="submit" id="tags-clean" value="'. get_lang('SearchResetKeywords') .'" />
</td>
</tr>
</table>
</div>
<br /><br />';
$list = get_specific_field_list();
if(!empty($list)) {
$form .=' <span class="search-links-box">'. $thesaurus_icon . $advanced_options .'&nbsp;</span>
<div id="tags" class="tags" style="display:'. $display_thesaurus .';">
<div class="search-help-box">'. $help .'</div>
<table>
<tr>';
if (!is_null($prefilter_prefix)) {
//sorting the array of terms
$temp = array();
foreach ($sf_terms[$prefilter_prefix] as $key => $value) {
$temp[trim(stripslashes($value['name']))] = $key;
}
$temp = array_flip($temp);
unset($sf_term_array);
natcasesort($temp);
$sf_term_array = $temp;
// get specific field name
$sf_value = get_specific_field_list(array( 'code' => "'$prefilter_prefix'" ));
$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);
} else {
$form .= format_specific_fields_selects($sf_terms, $op);
}
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"';
} else if ($op == 'and') {
$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 />
<input class="lower-submit" type="submit" value="'. get_lang('Search') .'" />
<input type="submit" id="tags-clean" value="'. get_lang('SearchResetKeywords') .'" />
</td>
</tr>
</table>
</div>';
}
$form .= '
</form>
<br style="clear: both;"/>
';
<br style="clear: both;"/>';
return $form;
}

@ -58,42 +58,46 @@ class document_processor extends search_processor {
* Get document information
*/
private function get_information($course_id, $doc_id) {
$doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT);
$item_property_table = Database::get_course_table_from_code($course_id, TABLE_ITEM_PROPERTY);
$doc_id = Database::escape_string($doc_id);
$sql = "SELECT *
FROM $doc_table
WHERE $doc_table.id = $doc_id
LIMIT 1";
$dk_result = Database::query ($sql);
$sql = "SELECT insert_user_id
FROM $item_property_table
WHERE ref = $doc_id
AND tool = '". TOOL_DOCUMENT ."'
LIMIT 1";
$name = '';
if ($row = Database::fetch_array ($dk_result)) {
$name = $row['title'];
$url = api_get_path(WEB_PATH) . 'courses/%s/document%s';
$url = sprintf($url, api_get_course_path($course_id), $row['path']);
// Get the image path
include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php';
$icon = choose_image(basename($row['path']));
$thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon;
$image = $thumbnail;
//FIXME: use big images
// get author
$author = '';
$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']);
}
$course_information = api_get_course_info($course_id);
if (!empty($course_information)) {
$item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_information['db_name']);
$doc_table = Database::get_course_table(TABLE_DOCUMENT, $course_information['db_name']);
$doc_id = Database::escape_string($doc_id);
$sql = "SELECT *
FROM $doc_table
WHERE $doc_table.id = $doc_id
LIMIT 1";
$dk_result = Database::query ($sql);
$sql = "SELECT insert_user_id
FROM $item_property_table
WHERE ref = $doc_id
AND tool = '". TOOL_DOCUMENT ."'
LIMIT 1";
$name = '';
if ($row = Database::fetch_array ($dk_result)) {
$name = $row['title'];
$url = api_get_path(WEB_PATH) . 'courses/%s/document%s';
$url = sprintf($url, api_get_course_path($course_id), $row['path']);
// Get the image path
include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php';
$icon = choose_image(basename($row['path']));
$thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon;
$image = $thumbnail;
//FIXME: use big images
// get author
$author = '';
$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
*/
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);
$doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT);
$lp_id = Database::escape_string($lp_id);
$course_information = api_get_course_info($course_id);
if (!empty($course_information)) {
$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) {
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path
FROM $lp_table, $lpi_table
INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id
WHERE $lpi_table.lp_id = $lp_id
AND $lpi_table.display_order = 1
AND $lp_table.id = $lpi_table.lp_id
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;
if ($has_document_id) {
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path
FROM $lp_table, $lpi_table
INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id
WHERE $lpi_table.lp_id = $lp_id
AND $lpi_table.display_order = 1
AND $lp_table.id = $lpi_table.lp_id
LIMIT 1";
}
$image = '';
if (!empty($big_img_path)) {
$image = $img_location . $big_img_path;
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";
}
$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
/* For licensing terms, see /license.txt */
require_once 'xapian.php';
require_once dirname(__FILE__) . '/../IndexableChunk.class.php';
@ -59,21 +61,19 @@ abstract class XapianIndexer {
$path = api_get_path(SYS_PATH).'searchdb/';
try {
$this->db = new XapianWritableDatabase($path, $dbMode);
$this->indexer = new XapianTermGenerator();
if (!in_array($lang, $this->xapian_languages())) {
$lang = 'english';
}
$this->db = new XapianWritableDatabase($path, $dbMode);
$this->indexer = new XapianTermGenerator();
$this->stemmer = new XapianStem($lang);
$this->indexer->set_stemmer($this->stemmer);
return $this->db;
}
catch (Exception $e) {
Display::display_error_message($e->getMessage());
return 1;
if (!in_array($lang, $this->xapian_languages())) {
$lang = 'english';
}
$this->stemmer = new XapianStem($lang);
$this->indexer->set_stemmer($this->stemmer);
return $this->db;
} 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
*/
function index() {
try {
if (!empty($this->chunks)) {
foreach ($this->chunks as $chunk) {
$doc = new XapianDocument();
$this->indexer->set_document($doc);
if (!empty($chunk->terms)) {
foreach ($chunk->terms as $term) {
/* FIXME: think of getting weight */
$doc->add_term($term['flag'] . $term['name'], 1);
try {
if (!empty($this->chunks)) {
foreach ($this->chunks as $chunk) {
$doc = new XapianDocument();
$this->indexer->set_document($doc);
if (!empty($chunk->terms)) {
foreach ($chunk->terms as $term) {
/* FIXME: think of getting weight */
$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
*/
function remove_document($did) {
if ($this->db == NULL) {
$this->connectDb();
}
if (is_numeric($did) && $did>0) {
$doc = $this->get_document($did);
if ($doc !== FALSE) {
$this->db->delete_document($did);
$this->db->flush();
}
}
if ($this->db == NULL) {
$this->connectDb();
}
if (is_numeric($did) && $did>0) {
$doc = $this->get_document($did);
if ($doc !== FALSE) {
$this->db->delete_document($did);
$this->db->flush();
}
}
}
/**
@ -294,5 +292,4 @@ abstract class XapianIndexer {
unset($this->db);
unset($this->stemmer);
}
}
?>
}

@ -27,16 +27,17 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
try {
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
$subqueries = array();
foreach ($extra as $subquery) {
if (!empty($subquery)) {
$subqueries[] = new XapianQuery($subquery);
}
if (!empty($subquery)) {
$subqueries[] = new XapianQuery($subquery);
}
}
$query = NULL;
$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_stemming_strategy(XapianQueryParser::STEM_SOME);
$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 = new XapianQuery(XapianQuery::OP_AND, array_merge($subqueries, array($query)));
}
else {
$query = new XapianQuery(XapianQuery::OP_OR, $subqueries);
$final_array = array_merge($subqueries, array($query));
$query = new XapianQuery(XapianQuery::OP_AND, $final_array);
} else {
$query = new XapianQuery(XapianQuery::OP_OR, $subqueries);
}
$enquire->set_query($query);
$matches = $enquire->get_mset((int)$start, (int)$length);
$specific_fields = get_specific_field_list();
$results = array();
$i = $matches->begin();
// Display the results.
//echo $matches->get_matches_estimated().'results found';
$count = 0;
while (!$i->equals($matches->end())) {
$count++;
$document = $i->get_document();
if (is_object($document)) {
// process one item terms
$courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID);
$results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1);
$toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID);
$results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1);
// 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());
}
$i->next();
while (!$i->equals($matches->end())) {
$count++;
$document = $i->get_document();
if (is_object($document)) {
// process one item terms
$courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID);
$results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1);
$toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID);
$results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1);
// 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());
}
$i->next();
}
switch ($count_type) {
@ -101,7 +112,6 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
$count = $matches->get_matches_estimated();
break;
}
return array($count, $results);
} catch (Exception $e) {
display_xapian_error($e->getMessage());

@ -158,9 +158,9 @@ class SortableTable extends HTML_Table {
$this->total_number_of_items = -1;
$this->get_total_number_function = $get_total_number_function;
$this->get_data_function = $get_data_function;
$this->column_filters = array ();
$this->form_actions = array ();
$this->checkbox_name = null;
$this->column_filters = array();
$this->form_actions = array();
$this->checkbox_name = null;
$this->td_attributes = array ();
$this->th_attributes = array ();
$this->other_tables = array();
@ -838,7 +838,7 @@ class SortableTableFromArray extends SortableTable {
* @param int $default_column
* @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);
$this->table_data = $table_data;
}
@ -847,7 +847,7 @@ class SortableTableFromArray extends SortableTable {
* Get table data to show on current page
* @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) {
$content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
} else {

@ -1,43 +1 @@
.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(\'../img/search_background_bar.jpg\');
background-repeat: repeat-x
}
#mode-selector {
width: 100px;
padding: 4px;
position: absolute;
top: 0px;
z-index: 9;
}
/* css styles moved to search_widget.css */

@ -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.
$fixed_queries = array();
$course_filter = NULL;
if ( ($cid=api_get_course_id()) != -1 ) {
if ( ($cid=api_get_course_id()) != -1 ) {
// Results only from actual course.
$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);
if ($course_filter != NULL) {
$fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and');
}
} else {
if (!empty($query)) {
if (!empty($query)) {
$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);
// Prepare blocks to show.
$blocks = array();
if ($count > 0) {
foreach ($results as $result) {
// Fill the result array.
@ -122,10 +134,8 @@ if ($count > 0) {
$a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'],
);
} else {
$title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? $result['author'] : '').'<div>';
$blocks[] = array(
$title,
);
$title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? ' '.$result['author'] : '').'<div>';
$blocks[] = array($title);
}
}
}
@ -158,7 +168,7 @@ if (count($blocks) > 0) {
$s->additional_parameters = $additional_parameters;
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">';

@ -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