12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- require 'xapian/XapianQuery.php';
- function chamilo_query_query($query_string, $offset = 0, $length = 10, $extra = null)
- {
- list($count, $results) = xapian_query($query_string, null, $offset, $length, $extra);
- return chamilo_preprocess_results($results);
- }
- function chamilo_query_simple_query($query_string, $offset = 0, $length = 10, $extra = null)
- {
- return xapian_query($query_string, null, $offset, $length, $extra);
- }
- function chamilo_get_boolean_query($term)
- {
- return xapian_get_boolean_query($term);
- }
- function chamilo_preprocess_results($results)
- {
-
- $results_by_tool = [];
- if (count($results) > 0) {
- foreach ($results as $key => $row) {
- $results_by_tool[$row['toolid']][] = $row;
- }
- $processed_results = [];
- foreach ($results_by_tool as $toolid => $rows) {
- $tool_processor_class = $toolid.'_processor';
- $tool_processor_path = api_get_path(LIBRARY_PATH).'search/tool_processors/'.$tool_processor_class.'.class.php';
- if (file_exists($tool_processor_path)) {
- require_once $tool_processor_path;
- $tool_processor = new $tool_processor_class($rows);
- $processed_results = array_merge($tool_processor->process(), $processed_results);
- }
- }
- return [count($processed_results), $processed_results];
- }
- }
- function chamilo_join_queries($query1, $query2 = null, $op = 'or')
- {
- return xapian_join_queries($query1, $query2, $op);
- }
|