definitions in schema.xml or schema-solr3.xml // //$query->addFilter("is_uid", 1); // //On s'assure que l'on applique un OU entre les termes de recherches // $query->replaceParam('mm', '1'); // } // //Modification du retour de la fonction apachesolr_search_page() // function thesaurus_suggest_apachesolr_search_page_alter(&$build, $search_page){ // //Les suggestions sont placées dans un bloc spécifique // unset($build['suggestions']); // //dsm($build); // } // /** // * Implements hook_block_info(). // */ // function thesaurus_suggest_block_info() { // $blocks['suggest'] = array( // 'info' => t('Apache Solr Suggest'), // 'cache' => DRUPAL_CACHE_PER_PAGE, // ); // return $blocks; // } // /** // * Implements hook_block_view(). // */ // function thesaurus_suggest_block_view($delta) { // if ('suggest' == $delta) { // $environments = apachesolr_load_all_environments(); // foreach ($environments as $env_id => $environment) { // if (apachesolr_has_searched($env_id) && !apachesolr_suppress_blocks($env_id)) { // $response =null; // // Get the query and response. Without these no blocks make sense. // $my_suggestions = array( // 'links' => array() // ); // if ($query = apachesolr_current_query($env_id)) { // //Quelle est la requête en cours // $q = $query->getParam('q'); // //Y a t'il déjà des suggestions Solr // $response = apachesolr_static_response_cache($query->getSearcher()); // $search_page = apachesolr_search_page_load('core_search'); // //Suggestions de Solr // if(isset($response->spellcheck->suggestions)){ // foreach($response->spellcheck->suggestions as $key=>$s){ // $my_suggestions['links'][] = ''.t('try this spelling').' : '.l($s->suggestion[0], $search_page['search_path'].'/'.$s->suggestion[0]); // } // } // //Suggestions du thésaurus // if($q!=''){ // $search_term=thesaurus_suggest_clean_term($q); // $suggestions = thesaurus_suggest_get_suggest($q);// // if(!empty($suggestions)){ // //Mise en forme des suggestions // //les synonymes // $t_op = t(' OR '); // if(!empty($suggestions['concept'])){ // if($search_term != thesaurus_suggest_clean_term($suggestions['concept']['search_str'])){ // $my_suggestions['links'][] = ''.t('search with synonyms').' :'.l(str_replace(' OR ', $t_op, $suggestions['concept']['search_str']), $search_page['search_path'].'/'.str_replace(' OR ', ' ', $suggestions['concept']['search_str'])); // } // } // //Ne chercher que sur le terme principal // if($search_term != thesaurus_suggest_clean_term($suggestions['concept']['id'])){ // $my_suggestions['links'][] = ''.t('search with the main term').' :'.l('"'.$suggestions['concept']['id'].'"', $search_page['search_path'].'/"'.$suggestions['concept']['id'].'"'); // } // //Ne chercher que sur un des synonymes // if(!empty($suggestions['concept']['altLabel'])){ // $syno =array(); // foreach($suggestions['concept']['altLabel'] as $altLabel){ // if($search != thesaurus_suggest_clean_term($altLabel)){ // $syno[]=l('"'.$altLabel.'"', $search_page['search_path'].'/"'.$altLabel.'"'); // } // } // if(!empty($syno)){ // $my_suggestions['links'][] =theme('item_list', array('items'=>$syno, 'title'=>t('on alternatives terms'))); // } // } // //termes spécifiques // if(!empty($suggestions['links']['narrower'])){ // $suggest_narrower = array(); // foreach($suggestions['links']['narrower'] as $n){ // $suggest_narrower[]=l(str_replace(' OR ', $t_op, $n['search_str']) , $search_page['search_path'].'/'.str_replace(' OR ', ' ', $n['search_str'])); // } // $my_suggestions['links'][] =theme('item_list', array('items'=>$suggest_narrower, 'title'=>t('on narrowers terms'))); // } // //termes génériques // if(!empty($suggestions['links']['broader'])){ // $suggest_broader = array(); // foreach($suggestions['links']['broader'] as $n){ // $suggest_broader[]=l(str_replace(' OR ', $t_op, $n['search_str']) , $search_page['search_path'].'/'.str_replace(' OR ', ' ', $n['search_str'])); // ''..''; // } // $my_suggestions['links'][] =theme('item_list', array('items'=>$suggest_broader, 'title'=>t('on broaders terms'))); // } // //termes associés // if(!empty($suggestions['links']['related'])){ // $suggest_related = array(); // foreach($suggestions['links']['related'] as $n){ // $suggest_related[]=l(str_replace(' OR ', t(' OR '), $n['search_str']) , $search_page['search_path'].'/'.str_replace(' OR ', ' ', $n['search_str'])); // ''..''; // } // $my_suggestions['links'][] =theme('item_list', array('items'=>$suggest_related, 'title'=>t('on related terms'))); // } // } // } // } // // Returns the sort form. // return array( // 'subject' => t('Suggestions'), // 'content' => theme('apachesolr_search_suggestions',$my_suggestions) //drupal_get_form('apachesolr_sort_sort_form_', $new_query, $sorts, $solrsort), // ); // } // } // } // } // //Fonction de theme qui surcharge le fonctionnement normale de la fonction theme_apachesolr_search_suggestions // function theme_thesaurus_suggest_apachesolr_search_suggestions($variables) { // $output =''; // if(!empty($variables['links'])){ // $content ='

Vous pouvez relancer des recherches complémentaires en utilisant les suggestions du ©Thésaurus Eau et du moteur de recherche en recherchant :

'; // $content.= theme('item_list', array('items'=>$variables['links'])); // $output = theme('fieldset', array( // 'element' => array( // // list title // '#title' => t('Search suggestions'), // '#children' => $content, // '#collapsible' => true, // '#collapsed' => true, // // we indicate in attributes that specified classes must be used // '#attributes' => array( // 'class' => array('collapsible', 'collapsed', 'search-suggestions') // ), // ))); // } // return $output; // } /** * Implementation of hook_form_FORM_ID_alter(). */ function thesaurus_suggest_form_search_form_alter(&$form, $form_state) { if ($form['module']['#value'] == 'apachesolr_search' || $form['module']['#value'] == 'apachesolr_multisitesearch') { thesaurus_suggest_search_form_do_alter($form); } } /** * Implementation of hook_form_FORM_ID_alter(). */ function thesaurus_suggest_form_search_block_form_alter(&$form, $form_state) { thesaurus_suggest_search_form_do_alter($form); } function thesaurus_suggest_search_form_do_alter(&$form){ //On ajoute l'arbre de navigation dans le Thésaurus Eau /*$form['actions']['thesaurus_tree'] = array( '#type' => 'button', '#value' => 'T©Thésaurus Eau', );*/ //On ajoute les js et css pour l'arbre D3JS $form['#attached']['css'][] = drupal_get_path('module', 'thesaurus_suggest') . '/css/style.css'; $form['#attached']['js'][] = array( 'data'=>'sites/all/libraries/d3Tooltip/Tooltip.js', 'type'=>'file' ); $form['#attached']['js'][] = array( 'data'=>array('thesau_src_file_path'=>drupal_get_path('module', 'thesaurus_suggest').'/thesaurus.json'), 'type'=>'setting', ); $form['#attached']['js'][] = array( 'data'=>drupal_get_path('module', 'thesaurus_suggest') . '/js/thesaurus_tree.js', 'type'=>'file' ); libraries_load('d3.drupal'); drupal_add_library('system', 'ui.dialog'); drupal_add_library('system', 'ui.autocomplete'); } function thesaurus_suggest_clean_term($term){ return str_replace('"', '', strtolower($term)); } // TODO :améliorer le fonctionnement afin de prendre en compte les recherches plus complexe // function thesaurus_suggest_get_suggest($plain_search){ // if(trim($plain_search)!=''){ // $search = thesaurus_suggest_clean_term($plain_search); // //Try to use the cache // $cid = 'thesaurus_suggest_matrix'; // if($cache = cache_get($cid)){ // $thesau = $cache->data['thesau']; // $matrix = $cache->data['matrix']; // } // else{ // $thesau = getThesaurusFile(); // $matrix = preProcessThesaurusForSearch($thesau); // cache_set($cid, array('thesau'=>$thesau, 'matrix'=>$matrix)); // } // $suggest = ''; // //Le mot existe ? // if(isset($matrix[$search])){ // $term['concept'] = $matrix[$search]; // //On regarde s'il n'est pas lié avec d'autres concepts // $l = getThesaurusLink($term['concept']['id'], $thesau->links); // if(!empty($l)){ // foreach($l as $link){ // $id= strtolower($link->id); // if(isset($matrix[$id])){ // $term['links'][$link->type][$id] = $matrix[$id]; // } // } // } // return $term; // } // } // //Si on arrive ici, c'est qu'on a rien trouver // return false; // } // function getThesaurusLink($id, $Tlinks){ // $links =array(); // foreach($Tlinks as $link){ // if($link->source==$id || $link->target==$id){ // $key_st = $link->source.'_'.$link->target; // $key_ts = $link->target.'_'.$link->source; // //Si l'info n'est pas déjà présente // if(!isset($links[$key_st]) && !isset($links[$key_ts])){ // $link->id=($link->source!=$id?$link->source:$link->target); //On cherche quel est le bon id de l'élément lié // $links[$key_st] = $link; // } // } // } // return $links; // } // //Cette fonction permet de charger le fichier source du thesaurus au format JSON // function getThesaurusFile(){ // return json_decode(file_get_contents(__DIR__ .'/thesaurus.json')); // } // //Cette fonction permet de générer une matrice utilisable pour la recherche d'un terme du thésaurus // function preProcessThesaurusForSearch($json){ // $map=array(); // foreach($json->nodes as $idx=>$node){ // if($node->type=='terme'){ // $search_str = makeThesaurusSearchString($node); // $id = $node->id; // $data = array( // 'idx'=>$idx, // 'id'=>$id, // 'search_str'=>$search_str, // 'altLabel'=>(isset($node->alt_label)?$node->alt_label:null), // ); // $map[strtolower($search_str)] = $data; // $map[strtolower($node->label)] = $data; // if(!empty($node->alt_label)){ // foreach($node->alt_label as $label){ // $map[strtolower($label)] = $data; // } // } // } // } // return $map; // } // function makeThesaurusSearchString($n){ // $str ='"'.$n->label.'"'.(!empty($n->alt_label)?' OR "'.implode('" OR "', $n->alt_label).'"':''); // return $str; // }