Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/main/search/search_suggestions.php

103 lines
4.4 KiB

[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
<?php
/*
* Suggest words to search
*/
require_once dirname(__FILE__) . '/../inc/global.inc.php';
function get_suggestions_from_search_engine($q) {
if (strlen($q)<2) { return null;}
global $charset;
$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);
[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
$data = array();
$i = 0;
while ($row = Database::fetch_array($sql_result)) {
echo api_convert_encoding($row['value'],'UTF-8',$charset)."| value\n";
[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
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 = array();
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 = array();
$field_val = array();
$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)
[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
$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
[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
// 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) . "| value\n";
[svn r17550] search: refactor search engine index and search interface and let learnpath follow it Search engine: - Index - use wrapper methods instead on calling xapian.php directly in most of callings - improve dokeos xapian-API - XapianIndexer - new methods: - replace_document() - remove_term_from_doc() - add_term_to_doc() - DokeosIndexer - new methods: - dokeos_preprocess_results() - Preprocess all results depending on the toolid - set_terms() - general interface for getting, comparing and set search engine terms - get_terms_on_db() - Get the terms stored at database (normal, no xapian) - more wrappers for XapianIndexer methods: dokeos_query_query(), dokeos_query_query(), dokeos_get_boolean_query(), dokeos_join_queries() - remove tags search engine feature to replace it with a new generic feature: specific fields - it let define xapian prefix terms dinamically to be included across dokeos index on each tool - move search engine document ID field from lp item table to a general man db table search_engine_ref - Search - use search_engine processor classes to change how process results depending of the dokeos tool - change interface for terms select at search: now use one multiple select foreach specific field instead of jquery thickbox plugin only for tags - search ajax suggestion feature to query terms on db - it need some work Learnpath: - refactor search engine pieces to use new tables search_engine_ref, specific_field and specific_field_values - add scorm and woogie index - remove search widget from lp list and use it from main/search - also, there are part on audios on lp items feature added
16 years ago
if (!in_array($s,$more_sugg)) {
$more_sugg[] = $s;
}
}
}
}
}
foreach ($more_sugg as $sugg) {
echo $sugg;
}
}
$q = strtolower($_GET["q"]);
if (!$q) return;
//echo $q . "| value\n";
get_suggestions_from_search_engine($q);
?>