12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- class ChamiloIndexer extends XapianIndexer
- {
-
- public function set_terms(
- $terms_string,
- $prefix,
- $course_code,
- $tool_id,
- $ref_id_high_level,
- $ref_id_second_level,
- $search_did
- ) {
- $terms_string = trim($terms_string);
- $terms = explode(',', $terms_string);
- array_walk($terms, 'trim_value');
- $stored_terms = $this->get_terms_on_db($prefix, $course_code, $tool_id, $ref_id_high_level);
-
- if ((count(array_diff($terms, $stored_terms)) == 0) &&
- (count(array_diff($stored_terms, $terms)) == 0)
- ) {
- return false;
- }
- require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
-
- $doc = $this->get_document($search_did);
- $xapian_terms = xapian_get_doc_terms($doc, $prefix);
- $xterms = [];
- foreach ($xapian_terms as $xapian_term) {
- $xterms[] = substr($xapian_term['name'], 1);
- }
- $dterms = $terms;
- $missing_terms = array_diff($dterms, $xterms);
- $deprecated_terms = array_diff($xterms, $dterms);
-
- foreach ($missing_terms as $term) {
- $this->add_term_to_doc($prefix.$term, $doc);
- }
- foreach ($deprecated_terms as $term) {
- $this->remove_term_from_doc($prefix.$term, $doc);
- }
-
- if ((count($missing_terms) > 0) || (count($deprecated_terms) > 0)) {
- $this->replace_document($doc, (int) $search_did);
- }
- return true;
- }
-
- public function get_terms_on_db($prefix, $course_code, $tool_id, $ref_id)
- {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $terms = get_specific_field_values_list_by_prefix(
- $prefix,
- $course_code,
- $tool_id,
- $ref_id
- );
- $prefix_terms = [];
- foreach ($terms as $term) {
- $prefix_terms[] = $term['value'];
- }
- return $prefix_terms;
- }
- }
|