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

skala
Julio Montoya 14 years ago
parent f4056bddda
commit bd1ab08d8c
  1. 34
      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. 32
      main/inc/lib/search/search_widget.php
  8. 12
      main/inc/lib/search/tool_processors/document_processor.class.php
  9. 15
      main/inc/lib/search/tool_processors/learnpath_processor.class.php
  10. 11
      main/inc/lib/search/xapian/XapianIndexer.class.php
  11. 18
      main/inc/lib/search/xapian/XapianQuery.php
  12. 8
      main/inc/lib/sortabletable.class.php
  13. 44
      main/newscorm/lp_list_search.css
  14. 20
      main/newscorm/lp_list_search.php
  15. 2
      searchdb/readme.txt

@ -568,7 +568,6 @@ function handle_search() {
$form->addElement('html', get_lang('SearchPrefilterPrefix'));
} else {
$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,16 +616,19 @@ 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'));
}
@ -636,10 +638,34 @@ function handle_search() {
$data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable);
$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);
$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,13 +139,14 @@ 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>
';
<tr>';
$form .= format_specific_fields_selects($sf_terms, $op);
$or_checked = '';
$and_checked = '';
@ -170,8 +171,9 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) {
</td>
</tr>
</table>
</div>
</form>
</div>';
}
$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,13 +208,14 @@ 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>
<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();
@ -233,6 +237,8 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
} else {
$form .= format_specific_fields_selects($sf_terms, $op);
}
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
@ -256,10 +262,12 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op,
</td>
</tr>
</table>
</div>
</div>';
}
$form .= '
</form>
<br style="clear: both;"/>
';
<br style="clear: both;"/>';
return $form;
}

@ -58,8 +58,11 @@ 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);
$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
@ -92,8 +95,9 @@ class document_processor extends search_processor {
$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();
}
}
}
?>

@ -78,9 +78,13 @@ 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);
$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) {
@ -120,8 +124,9 @@ class learnpath_processor extends search_processor {
}
$name = $row['name'];
}
return array($thumbnail, $image, $name, $row['author']);
} else {
return array();
}
}
}
?>

@ -1,4 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
require_once 'xapian.php';
require_once dirname(__FILE__) . '/../IndexableChunk.class.php';
@ -65,13 +67,11 @@ abstract class XapianIndexer {
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) {
} catch (Exception $e) {
Display::display_error_message($e->getMessage());
return 1;
}
@ -127,12 +127,10 @@ abstract class XapianIndexer {
return $did;
}
}
}
catch (Exception $e) {
} catch (Exception $e) {
Display::display_error_message($e->getMessage());
exit(1);
}
}
/**
@ -295,4 +293,3 @@ abstract class XapianIndexer {
unset($this->stemmer);
}
}
?>

@ -38,6 +38,7 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
}
}
$query = NULL;
$enquire = new XapianEnquire($db);
@ -51,23 +52,33 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
$query_parser->add_boolean_prefix('courseid', XAPIAN_PREFIX_COURSEID);
$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 {
$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);
@ -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,8 +158,8 @@ 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->column_filters = array();
$this->form_actions = array();
$this->checkbox_name = null;
$this->td_attributes = array ();
$this->th_attributes = 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,6 +76,13 @@ 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.
}
}
}
}
@ -86,8 +93,10 @@ 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)) {
$fixed_queries = dokeos_join_queries($term_array, null, $op);
if ($course_filter != NULL) {
$fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and');
}
@ -97,10 +106,13 @@ if (count($term_array)) {
}
}
//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