This commit is contained in:
Xes
2025-08-14 22:37:50 +02:00
parent fb6d5d5926
commit 3641e93527
9156 changed files with 1813532 additions and 0 deletions

66
main/search/INSTALL Normal file
View File

@@ -0,0 +1,66 @@
INSTALLATION
On Debian Lenny
Base install
apt-get install php5-xapian
(you need version 1.x of Xapian here - check xapian.org for older Deb/Ub)
two bugs:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=493944
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=493941
on dokeos root:
mkdir app/upload/plugins/xapian/searchdb
chmod 777 app/upload/plugins/xapian/searchdb (or equivalent)
Useful xapian development tools
apt-get install xapian-doc xapian-tools
(See delve command)
On Ubuntu 8.10
Chamilo 1.8.8 + XAPIAN in Ubuntu 10.10
1. Activate the search module setting in main/admin/settings.php?category=Search
2. Go to main/admin/specific_fields.php and Specific fields (Those are text fields that will be add in documents, exercises, links in order to index data)
i.e i.e. Author, Body part, Technology, Topic
3. Go to main/admin/settings.php?category=Search and set a Specific field by default
4. Install the Xapian module for PHP5
sudo apt-get install php5-xapian
5. Install the imagemagick modules
sudo apt-get install imagemagick
sudo apt-get install php5-imagick
6. In Chamilo root
mkdir app/upload/plugins/xapian/searchdb
sudo chmod 777 app/upload/plugins/xapian/searchdb
7. Useful Xapian development tools
sudo apt-get install xapian-doc xapian-tools
8. Restart Apache
9. Create a course and 2 *new* Learning paths for testing
10.Edit the LPs created and add/edit the specific fields (i.e. Author, Body part, Technology, Topic)
11.Go to the
On Ubuntu 12.04
Chamilo 1.9.4 + Xapian in Ubuntu 12.04
Since php5-xapian bindings are not available due to license inconsistencies, you have to build the php5-xapian package yourself.
you can follow the instrucions on the xapian.org wiki: http://trac.xapian.org/wiki/FAQ/PHP%20Bindings%20Package
build packages:
sudo apt-get build-dep xapian-bindings
sudo apt-get install php5-dev php5-cli devscripts
apt-get source xapian-bindings
cd xapian-bindings-1.2.*
rm -f debian/control debian/*-stamp
env PHP_VERSIONS=5 debian/rules maint
sed -i 's!include_path=php5$!include_path=$(srcdir)/php5!' php/Makefile.in
echo auto-commit >> debian/source/options
debuild -e PHP_VERSIONS=5 -us -uc
cd ..
If you're using PHP 5.4, then subclassing Xapian classes in PHP doesn't currently work properly and the testsuite will fail with
a segmentation fault. The wrappers work otherwise, so if that's all you need, you can build the package without running the testsuite
by changing the penultimate command above to:
env DEB_BUILD_OPTIONS=nocheck debuild -e PHP_VERSIONS=5 -us -uc
Then you can install the built package:
sudo dpkg -i php5-xapian_*.deb

29
main/search/NOTES Normal file
View File

@@ -0,0 +1,29 @@
Development information
Compiling the modified OogieDocumentConverter.java(note target):
javac -cp .:commons-cli-1.0.jar:commons-io-1.3.1.jar:edtftpj-1.5.2.jar:java_uno_accessbridge.jar:java_uno.jar:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar:juh-2.3.0.jar:jurt-2.3.0.jar:jut.jar:oogie.jar:ridl-2.3.0.jar:ridl.jar:slf4j-api-1.4.3.jar:slf4j-jdk14-1.4.3.jar:unoil-2.3.0.jar:xstream-1.2.2.jar -sourcepath commons-cli-1.0.jar:commons-io-1.3.1.jar:edtftpj-1.5.2.jar:java_uno_accessbridge.jar:java_uno.jar:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar:juh-2.3.0.jar:jurt-2.3.0.jar:jut.jar:oogie.jar:ridl-2.3.0.jar:ridl.jar:slf4j-api-1.4.3.jar:slf4j-jdk14-1.4.3.jar:unoil-2.3.0.jar:xstream-1.2.2.jar -target 1.5 OogieDocumentConverter.java
Debugging help:
error_log('info: id = <'. $id .'>');
echo Display::return_message(print_r($arrLP,1));
DB modifications:
ALTER TABLE lp_item ADD terms TEXT NULL ;
ALTER TABLE lp_item ADD search_did INT(10) NULL
-- on every course, so it's pending(TODO):
-- script to generate it for all courses depending of the type of dokeos intalation(one db or many)
-- create it when a course is created
About search:
Xapian support two main ways of search: probabilistic and boolean.
- Probabilistic: search in all index_text() info indexed to xapian
- Boolean: search in xapian terms(doc have the term or not), depending on prefix
About terms:
It's assumed that terms(tags) have only 1 word and are stored at a CVS string in dokeos DB
Prefixs:
Each term in xapian DB would have a prefix depending of the tipe of term.
Here is the actual propossed list:
- 'T': tags(free tagging), stored in db
- 'F': filetype(form source), not stored in db only one term
- 'C': course id

19
main/search/index.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file includes lp_list_search to avoid duplication of code, it
* bootstraps chamilo api enough to make lp_list_search work.
*
* @package chamilo.search
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
if (extension_loaded('xapian')) {
require '../lp/lp_list_search.php';
} else {
Display::display_header(get_lang('Search'));
echo Display::return_message(get_lang('SearchXapianModuleNotInstalled'), 'error');
Display::display_footer();
exit;
}

View File

@@ -0,0 +1,125 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Suggest words to search.
*
* @package chamilo.search
*/
require_once __DIR__.'/../inc/global.inc.php';
function get_suggestions_from_search_engine($q)
{
global $charset;
$json = [];
$table_sfv = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$q = Database::escape_string($q);
$cid = api_get_course_id();
$sql_add = '';
if ($cid != -1) {
$sql_add = " AND course_code = '".$cid."' ";
}
$sql = "SELECT * FROM $table_sfv where value LIKE '%$q%'".$sql_add."
ORDER BY course_code, tool_id, ref_id, field_id";
$sql_result = Database::query($sql);
$data = [];
$i = 0;
while ($row = Database::fetch_array($sql_result)) {
$json[] = [
'id' => api_convert_encoding($row['value'], 'UTF-8', $charset),
'value' => api_convert_encoding($row['value'], 'UTF-8', $charset),
'label' => api_convert_encoding($row['value'], 'UTF-8', $charset),
];
if ($i < 20) {
$data[$row['course_code']][$row['tool_id']][$row['ref_id']] = 1;
}
$i++;
}
// now that we have all the values corresponding to this search, we want to
// make sure we get all the associated values that could match this one
// initial value...
$more_sugg = [];
foreach ($data as $cc => $course_id) {
foreach ($course_id as $ti => $item_tool_id) {
foreach ($item_tool_id as $ri => $item_ref_id) {
//natsort($item_ref_id);
$output = [];
$field_val = [];
$sql2 = "SELECT * FROM $table_sfv
WHERE course_code = '$cc' AND tool_id = '$ti' AND ref_id = '$ri'
ORDER BY field_id";
$res2 = Database::query($sql2);
// TODO this code doesn't manage multiple terms in one same field just yet (should duplicate results in this case)
$field_id = 0;
while ($row2 = Database::fetch_array($res2)) {
//TODO : this code is not perfect yet. It overrides the
// first match set, so having 1:Yannick,Julio;2:Rectum;3:LASER
// will actually never return: Yannick - Rectum - LASER
// because it is overwriteen by Julio - Rectum - LASER
// We should have recursivity here to avoid this problem!
//Store the new set of results (only one per combination
// of all fields)
$field_val[$row2['field_id']] = $row2['value'];
$current_field_val = '';
foreach ($field_val as $id => $val) {
$current_field_val .= $val.' - ';
}
//Check whether we have a field repetition or not. Results
// have been ordered by field_id, so we should catch them
// all here
if ($field_id == $row2['field_id']) {
//We found the same field id twice, split the output
// array to allow for two sets of results (copy all
// existing array elements into copies and update the
// copies) eg. Yannick - Car - Driving in $output[1]
// will create a copy as Yannick - Car - Speed
// in $output[3]
$c = count($output);
for ($i = 0; $i < $c; $i++) {
$output[($c + $i)] = $current_field_val;
}
} else {
//no identical field id, continue as usual
$c = count($output);
if ($c == 0) {
$output[] = $row2['value'].' - ';
} else {
foreach ($output as $i => $out) {
//use the latest combination of fields
$output[$i] .= $row2['value'].' - ';
}
}
$field_id = $row2['field_id'];
}
}
foreach ($output as $i => $out) {
if (api_stristr($out, $q) === false) {
continue;
}
$s = api_convert_encoding(substr($out, 0, -3), 'UTF-8', $charset);
if (!in_array($s, $more_sugg)) {
$more_sugg[] = $s;
$json[] = [
'id' => $s,
'value' => $s,
'label' => $s,
];
}
}
}
}
}
echo json_encode($json);
}
if (isset($_GET['term'])) {
$q = strtolower($_GET['term']);
if (!$q) {
return;
}
get_suggestions_from_search_engine($q);
}