فهرست منبع

Merge branch 'bettersearch' into prod
added advanced to prod branch for inline production

Bachir Soussi Chiadmi 10 سال پیش
والد
کامیت
88d4cf09dc
5فایلهای تغییر یافته به همراه554 افزوده شده و 49 حذف شده
  1. 23 3
      materio_search_api.admin.inc
  2. 390 13
      materio_search_api.module
  3. 80 29
      materio_search_api.pages.inc
  4. 50 2
      materio_taxonomy.module
  5. 11 2
      templates/materio-search-api-search-block.tpl.php

+ 23 - 3
materio_search_api.admin.inc

@@ -7,11 +7,11 @@ function materio_search_api_settings(){
 	foreach ($indexes as $machine_name => $index) {
 		if($index->status == 1)
 			$index_options[$index->machine_name] = $index->name;
-	}		
+	}
 
 	$languages = locale_language_list();
 	// dsm($languages, 'languages');
-	
+
 	foreach ($languages as $lcode => $name) {
 		$form['mainsearchindex_'.$lcode] = array(
 			'#type'=>'select',
@@ -33,10 +33,17 @@ function materio_search_api_settings(){
 			'#default_value' => variable_get('autocompletesearchindex_'.$lcode, -1),
 			'#title' => t('Autocomplete search api index for %lang contents.', array('%lang'=>$name)),
 		);
+
+		$form['advancedsearchindex_'.$lcode] = array(
+			'#type'=>'select',
+			'#options'=>$index_options,
+			'#default_value' => variable_get('advancedsearchindex_'.$lcode, -1),
+			'#title' => t('Advanced search api index for %lang contents.', array('%lang'=>$name)),
+		);
 	}
 
 
-	// TODO:  select the activated viewmodes for change view mode and selected view mode  
+	// TODO:  select the activated viewmodes for change view mode and selected view mode
 	$entity_infos = entity_get_info();
   // dsm($entity_infos, 'entity_infos');
   foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
@@ -68,6 +75,19 @@ function materio_search_api_settings(){
 		);
 	}
 
+	$vocabularies = taxonomy_get_vocabularies();
+	// dsm($vocabularies, 'vocabularies');
+	foreach ($vocabularies as $vid => $voc){
+		$vocs_options[$vid] = $voc->name;
+	}
+
+	$form['advancedsearchvocs'] = array(
+		'#type'=>'select',
+		'#options'=>$vocs_options,
+		'#default_value' => variable_get('advancedsearchvocs', array()),
+		'#title' => t('Advanced Search Vocabularies'),
+		'#multiple' => true,
+	);
 
 	return system_settings_form($form);
 }

+ 390 - 13
materio_search_api.module

@@ -38,6 +38,10 @@ function materio_search_api_permission() {
       'title' => t('use Materio search api filters'),
       'description' => t('Use materio search api filters.'),
     ),
+    'use materio search api advanced search' => array(
+      'title' => t('use materio search api advanced search'),
+      'description' => t('Use materio search api advanced search.'),
+    ),
   );
 }
 
@@ -124,6 +128,12 @@ function materio_search_api_search_api_data_type_info() {
       'prefix' => 'temmap',
       'always multiValued' => TRUE,
     ),
+    // 'term_tid' => array(
+    //   'name' => t('Taxonomy term tid'),
+    //   'fallback' => 'integer',
+    //   'prefix' => 'im',
+    //   'always multiValued' => TRUE,
+    // ),
   );
 }
 
@@ -142,8 +152,11 @@ function materio_search_api_search_api_solr_dynamic_field_info() {
       'prefix' => 'temmap',
       'always multiValued' => TRUE,
     ),
+    // 'term_tid' => array(
+    //   'prefix' => 'im',
+    //   'always multiValued' => TRUE,
+    // ),
   );
-
 }
 
 
@@ -164,33 +177,39 @@ function materio_search_api_entity_property_info_alter(&$info){
     $node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
       'type'=>'text',
       'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
-      // 'query callback'=>'entity_metadata_table_query',
       'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text',
     );
+    $node_props['materio_search_api_onthologie_term_'.$i.'_tid'] = array(
+      'type'=>'text',
+      'label'=> t('Main onthologie term '.$i. ' as tid'),
+      'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_tid',
+    );
   }
 
   $node_props['materio_search_api_onthologie_term_others_text'] = array(
     'type'=>'list<text>',
     'label'=> t('Others onthologie terms as text (+ synonyms)'),
-    // 'query callback'=>'entity_metadata_table_query',
     'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
   );
 
+  $node_props['materio_search_api_onthologie_term_others_tid'] = array(
+    'type'=>'list<text>',
+    'label'=> t('Others onthologie terms as tid'),
+    'getter callback'=>'materio_search_api_get_taxonomy_terms_others_tid',
+  );
+
   $node_props['materio_search_api_taglibres_text'] = array(
     'type'=>'list<text>',
     'label'=> t('Tag libres terms as text (+ synonyms)'),
-    // 'query callback'=>'entity_metadata_table_query',
     'getter callback'=>'materio_search_api_get_taglibres_terms_text',
   );
 
 
-
   $node_materiau_props = &$info['node']['bundles']['materiau']['properties'];
 
   $node_materiau_props['materio_search_api_node_propertie_companie'] = array(
     'type'=>'list<text>',
     'label'=> t('Manufacturers and distributors companies localised (dont addresse)'),
-    // 'query callback'=>'entity_metadata_table_query',
     'getter callback'=>'materio_search_api_get_node_propertie_companie',
   );
 
@@ -204,9 +223,11 @@ function materio_search_api_entity_property_info_alter(&$info){
     'type' => 'text',
     'getter callback' => 'materio_search_api_term_property_dup_name',
   );
-
 }
 
+/**
+* taxonomy propoerties as text + synonymes
+*/
 function materio_search_api_get_onthologie_term_1_text($item){
   // dsm($item, 'item');
   return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 0);
@@ -288,6 +309,55 @@ function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta)
   return null;
 }
 
+/**
+* taxonomy properties as tid
+*/
+function materio_search_api_get_onthologie_term_1_tid($item){
+  // dsm($item, 'item');
+  return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 0);
+}
+function materio_search_api_get_onthologie_term_2_tid($item){
+  // dsm($item, 'item');
+  return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 1);
+}
+function materio_search_api_get_onthologie_term_3_tid($item){
+  // dsm($item, 'item');
+  return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 2);
+}
+function materio_search_api_get_onthologie_term_4_tid($item){
+  // dsm($item, 'item');
+  return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 3);
+}
+function materio_search_api_get_onthologie_term_5_tid($item){
+  // dsm($item, 'item');
+  return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 4);
+}
+
+function materio_search_api_get_taxonomy_terms_others_tid($item){
+  // dsm($item, 'item');
+  $delta = 5;
+  $terms = array();
+  while( isset($item->field_onthologie['und'][$delta]) ){
+    $terms[] = materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", $delta);
+    $delta++;
+  }
+  return $terms;
+}
+
+function materio_search_api_get_taxo_term_field_tid($item, $field_name, $delta){
+  // dsm($item, 'item');
+  // dsm($delta, 'delta');
+  $tid = null;
+  if(isset($item->{$field_name}['und'][$delta]))
+    $tid = $item->{$field_name}['und'][$delta]['tid'];
+
+  // print 'tid = '.$tid."\n";
+  return $tid;
+}
+
+/**
+*
+*/
 function materio_search_api_get_node_propertie_companie($item){
   // dsm($item, '$item');
   $lang = "fr";//$item->language;
@@ -365,12 +435,17 @@ function materio_search_api_term_property_dup_name($term){
  * Implements hook_block_info().
  */
 function materio_search_api_block_info() {
-  // This example comes from node.module.
   $blocks['materio_search_api_search'] = array(
     'info' => t('Materio search api search'),
     'cache' => DRUPAL_NO_CACHE
   );
 
+  $blocks['materio_sa_adv_search'] = array(
+    'info' => t('Materio search api advanced search'),
+    'cache' => DRUPAL_NO_CACHE
+  );
+
+  # NOT USED
   $blocks['materio_search_api_viewmode'] = array(
     'info' => t('Materio search api view mode selection'),
     'cache' => DRUPAL_NO_CACHE
@@ -420,6 +495,14 @@ function materio_search_api_block_view($delta = '') {
     //     $block['content'] = theme('materio_search_api_filters_block', array());
     //   }
     //   break;
+
+    # NOT USED
+    case 'materio_sa_adv_search':
+      if(user_access('use materio search api advanced search')){
+        $block['subject'] = t('Advanced Search');
+        $block['content'] = theme('materio_search_api_advanced_search_block', array());
+      }
+      break;
   }
   return $block;
 }
@@ -493,7 +576,20 @@ function materio_search_api_search_form($form, &$form_state){
 
   $args = arg();
   $path = array_shift($args);
-  $keys = implode('/', $args);
+  // dsm($args, 'args');
+  if($args[0] == "advanced"){
+    $advanced = true;
+    array_shift($args);
+    // dsm($args, 'shifted arsg');
+    // foreach ($args as $arg) {
+    //   $typed[] = $arg;//(integer)$arg;
+    // }
+    $keys = implode(' +', $args);
+  }else{
+    $keys = implode('/', $args);
+  }
+
+
 
   if(user_access('use materio search api autocomplete')){ // use materio search api autocomplete | use materio search api filters
     $query = new EntityFieldQuery();
@@ -509,7 +605,6 @@ function materio_search_api_search_form($form, &$form_state){
   $form['searchfield'] = array(
     '#type' => 'textfield',
     '#default_value' => $path == 'explore' ? $keys : $default_value, // TODO:  set the search page path global or a variable in settings
-    // '#value' => $keys,
     '#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
     //'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
     '#size' => 30,
@@ -583,9 +678,195 @@ function materio_search_api_search_form_submit($form, &$form_state){
 
 
 /**
- * viewmode
+ * materiobase_advancedsearch_form()
  */
+function materio_search_api_advanced_search_form($form, &$form_state){
+  //  dsm($form_state, 'form_state');
+  // dsm($form, 'form');
+  // global $user;
+
+  $keys = arg();
+  $path = array_shift($keys);
+  // dsm($keys, 'keys');
+  if($path == 'explore' && $keys[0] == "advanced"){
+    $advanced = true;
+    array_shift($keys);
+    $default_keys = $keys;
+  }
+
+  $form = array(
+    'title' => array(
+      '#prefix' => "<h3>",
+      '#markup' => t("Advanced Search"),
+      '#suffix' => "</h3>",
+    )
+  );
+
+  $vocabularies = variable_get('advancedsearchvocs', array());
+
+  $form['slider'] = array(
+    '#type' => 'fieldset',
+    // '#title' => $voc->name,
+    '#tree' => true,
+  );
+
+  foreach ($vocabularies as $vid) {
+    // dsm($vid, "vid");
+
+    $voc = taxonomy_vocabulary_load($vid);
+    // dsm($voc, 'voc');
+
+    $form['slider']['voc-'.$vid] = array(
+      '#type' => 'fieldset',
+      // '#title' => $voc->name,
+      '#tree' => true,
+    );
+
+    $tree = taxonomy_get_tree($vid, 0, 1, TRUE);
+    // dsm($tree, 'tree');
+
+    if(!count($tree))
+      continue;
+
+    foreach ($tree as $term) {
+      // dsm($term, "term");
+
+      $children = taxonomy_get_children($term->tid, $vid);
+      // dsm($children, "children");
+
+      if($term->field_used_on_advanced_search['und'][0]['value'] == 0
+        || !count($children))
+       continue;
+
+      $form['slider']['voc-'.$vid]['tree-'.$term->tid] = array(
+        '#type' => 'fieldset',
+        // '#title' => $term->name,
+        '#attributes' => array("class"=>array("treelevel1")),
+        '#tree' => true,
+      );
+
+      $placeholder = t("Select an option");
+      $form['slider']['voc-'.$vid]['tree-'.$term->tid]['children'] = array(
+        '#type' => 'select',
+        '#title' =>  $term->name,
+        '#attributes' => array(
+          "class"=>array("treelevel1"),
+          "title"=>$placeholder,
+          "data-placeholder" => $placeholder,
+        ), //, "form-control"
+        '#theme_wrappers' => array('materio_search_api_form_element'),
+        '#empty_option' => $placeholder,
+        '#empty_value' => 1,
+      );
+
+      $options = array();
+      foreach ($children as $tid => $child) {
+        // $child = taxonomy_term_load($child->tid);
+        // if($child->field_used_on_advanced_search['und'][0]['value'] == 0){
+        //  continue;
+        // }
+
+        $children2 = taxonomy_get_children($child->tid, $vid);
+        // dsm($children2, "children2");
+
+        if(count($children2))
+          $options[$tid] = $child->name;
+
+        $classes2 = array("treelevel2", $child->tid);
 
+        $options2 = [];
+        $dflt_values2 = [];
+        foreach ($children2 as $tid2 => $child2) {
+          // $child2 = taxonomy_term_load($child2->tid);
+          // if($child2->field_used_on_advanced_search['und'][0]['value'] == 0){
+          //  continue;
+          // }
+
+          $options2[$tid2] = $child2->name;
+
+          // default Values
+          if(in_array($tid2, $default_keys))
+            $dflt_values2[] = $tid2;
+
+        }
+
+        if(count($options2)){
+
+          if(count($dflt_values2))
+            $classes2[] = 'visible';
+
+          $form['slider']['voc-'.$vid]['tree-'.$term->tid]['tid-'.$child->tid] = array(
+            '#type' => 'select',
+            '#title' => $child->name,
+            '#multiple' => true,
+            '#attributes' => array(
+              "class" => $classes2, // , "form-control"
+              "title" => "-Please select-",
+              "tid" => $child->tid,
+            ),
+            '#theme_wrappers' => array('materio_search_api_form_element'),
+            // '#empty_option' => '-Please select-',
+            // '#empty_value' => 1,
+            '#options' => $options2,
+            '#default_value' => $dflt_values2,
+          );
+        }
+      }
+      if(count($options)){
+        $form['slider']['voc-'.$vid]['tree-'.$term->tid]['children']['#options'] = $options;
+      }else{
+        unset($form['slider']['voc-'.$vid]['tree-'.$term->tid]);
+      }
+    }
+
+  }
+
+  $form['slider']['show'] = array(
+    '#type' => 'image_button',
+    '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
+    '#value' => t('Find'),
+    // '#attributes' => array("class"=>array("btn","btn-lg")),
+    '#prefix' => '<div class="submits">',
+    '#suffix' => '</div>',
+  );
+  return $form;
+}
+
+function materio_search_api_advanced_search_form_validate($form, &$form_state){
+  // dsm($form, '$form');
+  // dsm($form_state, '$form_state');
+  // dsm(strlen($form_state['values']['searchfield']));
+  // if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
+  //   form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
+  // }
+}
+
+function materio_search_api_advanced_search_form_submit($form, &$form_state){
+  // dsm($form, 'form');
+  // dsm($form_state, 'form_state');
+  $fs_values = $form_state['values']['slider'];
+  unset($fs_values['show']);
+  // dsm($fs_values, 'values');
+
+  foreach($fs_values as $voc => $trees){
+    foreach($trees as $tree => $values){
+      foreach ($values as $values => $selected) {
+        if(is_array($selected) && count($selected)){
+          foreach ($selected as $tid) {
+            $tids[] = $tid;
+          }
+        }
+      }
+    }
+  }
+
+  $form_state['redirect'] = 'explore/advanced/'.implode('/', $tids);
+}
+
+
+/**
+ * viewmode
+ */
 function _materio_search_api_change_viewmode($vm){
   // dsm($vm, '_materio_search_api_change_viewmode');
 
@@ -656,7 +937,15 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
         'pager' => NULL,
         'count' => 0,
       )
-    )
+    ),
+    'materio_search_api_advanced_search_block' => array(
+      'template' => 'materio-search-api-advanced-search-block',
+      'path' => drupal_get_path('module', 'materio_search_api').'/templates',
+      'arguments' => array(),
+    ),
+    'materio_search_api_form_element' => array(
+      'render element' => 'element',
+    ),
   );
 }
 
@@ -677,6 +966,9 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
 function template_preprocess_materio_search_api_search_block(&$vars){
   // dsm($vars, '$vars');
   $vars['searchform'] = drupal_get_form("materio_search_api_search_form");
+  if(user_access('use materio search api advanced search')){
+    $vars['advancedsearchform'] = drupal_get_form("materio_search_api_advanced_search_form");
+  }
 }
 
 function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
@@ -842,7 +1134,6 @@ function template_preprocess_materio_search_api_results(array &$vars) {
   //dsm($vars, '$vars');
 }
 
-
 function template_preprocess_materio_search_api_actuality(&$vars){
   // dsm($vars, 'template_preprocess_materio_search_api_actuality | vars');
 
@@ -850,6 +1141,92 @@ function template_preprocess_materio_search_api_actuality(&$vars){
   $vars['actualities_infos'] = t('');
 }
 
+function template_preprocess_materio_search_api_advanced_search_block(&$vars){
+  // dsm($vars, "vars");
+  $vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
+}
+
+function theme_materio_search_api_form_element($variables) {
+  // dsm($variables, 'variables');
+
+  $element = &$variables['element'];
+
+  // This function is invoked as theme wrapper, but the rendered form element
+  // may not necessarily have been processed by form_builder().
+  $element += array(
+    '#title_display' => 'before',
+  );
+
+  // Add element #id for #type 'item'.
+  if (isset($element['#markup']) && !empty($element['#id'])) {
+    $attributes['id'] = $element['#id'];
+  }
+  // Add element's #type and #name as class to aid with JS/CSS selectors.
+  $attributes['class'] = array('form-item');
+  if (!empty($element['#type'])) {
+    $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
+  }
+  if (!empty($element['#name'])) {
+    $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
+  }
+  // Add a class for disabled elements to facilitate cross-browser styling.
+  if (!empty($element['#attributes']['disabled'])) {
+    $attributes['class'][] = 'form-disabled';
+  }
+
+  # adding element class to wrapper
+  foreach ($element['#attributes']['class'] as $value) {
+    $attributes['class'][] = $value;
+  }
+
+  foreach ($element['#attributes'] as $attr => $value) {
+    if(!in_array($attr, array('class', 'multiple', 'id', 'type', 'name'))){
+      $attributes[$attr] = $value;
+    }
+  }
+
+  $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
+
+
+  // If #title is not set, we don't display any label or required marker.
+  if (!isset($element['#title'])) {
+    $element['#title_display'] = 'none';
+  }
+  $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
+  $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
+
+  switch ($element['#title_display']) {
+    case 'before':
+    case 'invisible':
+      $output .= ' ' . theme('form_element_label', $variables);
+      $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
+      break;
+
+    case 'after':
+      $output .= ' ' . $prefix . $element['#children'] . $suffix;
+      $output .= ' ' . theme('form_element_label', $variables) . "\n";
+      break;
+
+    case 'none':
+    case 'attribute':
+      // Output no label and no required marker, only the children.
+      $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
+      break;
+  }
+
+  if (!empty($element['#description'])) {
+    $output .= '<div class="description">' . $element['#description'] . "</div>\n";
+  }
+
+  $output .= "</div>\n";
+
+  return $output;
+}
+
+
+
+
+
 /**
 * - - - - - - - - - - - -  SEARCH API PAGE  - - - - - - - - - - - -
 */

+ 80 - 29
materio_search_api.pages.inc

@@ -127,9 +127,21 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
 function materio_search_api_results_search(){
   //dsm("materio_search_api_results_search");
 
-  // retreive typed words separated by slahes as a sentence
-  $args = func_get_args();
-  $typed = implode('/', $args);
+  // retreive typed words separated by slashes as a sentence
+  $keys = func_get_args();
+  // dsm($args, 'args');
+  if($keys[0] == "advanced"){
+    $advanced = true;
+    array_shift($keys);
+    // dsm($keys, 'shifted keys');
+    // foreach ($args as $arg) {
+    //   $typed[] = $arg;//(integer)$arg;
+    // }
+    $typed = implode(' +', $keys);
+  }else{
+    $typed = implode('/', $keys);
+  }
+
 
   // remove query page params
   preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
@@ -142,8 +154,15 @@ function materio_search_api_results_search(){
   global $language;
   global $user;
 
-  if(user_access('use materio search api')){
-    // switch index depending on key words type full text or taxonomy term (autocomplete selection)
+  if($advanced && user_access('use materio search api advanced search')){
+    // dsm('advanced search');
+    $index_machine_name = variable_get('advancedsearchindex_'.$language->language, -1);
+    // dsm($index_machine_name, '$index_machine_name');
+    $index = search_api_index_load($index_machine_name);
+  }
+  else if(user_access('use materio search api')){
+    // dsm('normal search');
+    # switch index depending on key words type full text or taxonomy term (autocomplete selection)
     $searchmode = isset($user->data['materiosearchapi_searchmode']) ? $user->data['materiosearchapi_searchmode'] : "fulltext";
     switch($searchmode){
       case "fulltext":
@@ -155,60 +174,74 @@ function materio_search_api_results_search(){
       // break;
     }
     $index = search_api_index_load($index_machine_name);
-  }else if(user_access('use materio search api for breves')){
+  }
+  else if(user_access('use materio search api for breves')){
+    // dsm('limited search');
     $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
     // dsm($index_machine_name, '$index_machine_name');
     $index = search_api_index_load($index_machine_name);
   }
 
-  // potential results index for anonymous and free user
-  $could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
-  $could_index = search_api_index_load($index_machine_name);
+  if(!user_access('use materio search api advanced search') && !user_access('use materio search api')){
+    # potential results index for anonymous and free user
+    $could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
+    $could_index = search_api_index_load($index_machine_name);
+  }
 
   if ($typed) {
-    // TODO:  cache the results with cache graceful : http://drupal.org/project/cache_graceful
+    # TODO:  cache the results with cache graceful : http://drupal.org/project/cache_graceful
     try {
 
-      $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
-      // dsm($viewmode, 'viewmode');
+      # retrieve viewmode and then use it to define the query range
+      $viewmode = isset($user->data['materiosearchapi_viewmode'])
+        ? $user->data['materiosearchapi_viewmode']
+        : variable_get('defaultviewmode', 'full');
 
       $limit = variable_get($viewmode.'_limite', '10');
       $offset = pager_find_page() * $limit; //$page*$limit;//
 
       if(isset($index)){
 
-        // $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
-        // dsm($index_machine_name, '$index_machine_name');
+        # define default bundle option (materiaux, breves)
         $default_bundles = array();
         if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
           $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
           foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
         }
-
-        $bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
-        // dsm($bundles_filter, 'bundles_filter');
-
-        $query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
-          // ->keys(implode(' ', $keys))
+        # choose solr query bundle option
+        $bundles_filter = isset($user->data['materiosearchapi_bundlesfilter'])
+          ? $user->data['materiosearchapi_bundlesfilter']
+          : $default_bundles;
+
+        # choose solr query options
+        $query_options = $advanced
+          ? array('conjunction'=>'AND', 'parse mode'=>'direct')
+          : array('conjunction'=>'OR', 'parse mode'=>'direct');
+
+        #create the solr query
+        $query = search_api_query($index_machine_name, $query_options)
           ->keys($typed)
           ->range($offset, $limit);
 
+        # apply bundle options to solr query if usefull
         if(count($bundles_filter)){
           $filter = $query->createFilter('OR');
-          foreach ($bundles_filter as $type) {
+          foreach ($bundles_filter as $type)
             $filter->condition('type', $type, '=');
-          }
-          // dsm($filter, 'filter');
+
           $query->filter($filter);
         }
 
         // $query->setOption('search_api_bypass_access', true);
+
+        # add user access solr query option
         $query->setOption('search_api_access_account', $user);
 
+        # execute solr query and record results
         $results = $query->execute();
       }
 
-      # in case of utilisateur search, run a real search to indicate how much items you could find
+      # in case of free user search, run a real search to indicate how much items you could find
       if(isset($could_index)){
         $could_query = search_api_query($could_index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
         // ->keys(implode(' ', $keys))
@@ -226,11 +259,17 @@ function materio_search_api_results_search(){
     }
     // dsm($results, 'results');
 
-    if(user_access('use materio search api for breves') || user_access('use materio search api')){
-      if(user_access('use materio search api')){
-        $items = $index->loadItems(array_keys($results['results']));
+    if(user_access('use materio search api for breves')
+      || user_access('use materio search api')
+      || user_access('use materio search api advanced search'))
+    {
+      if(user_access('use materio search api') || user_access('use materio search api advanced search')){
+        if(is_array($results['results'])){
+          $items = $index->loadItems(array_keys($results['results']));
+        }else{
+          $items = array();
+        }
         // dsm($items, 'items');
-        // $count = $results['result count'];
       }
       else{
         $items = array();
@@ -275,8 +314,20 @@ function materio_search_api_results_search(){
     $ret['results']['#view_mode'] = $viewmode;
 
 
-    drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
+    // page title
+    if($advanced){
+      foreach($keys as $tid){
+        $t = taxonomy_term_load($tid);
+        $ptk[] = $t->name;
+      }
+      $page_title = implode(' +', $ptk);
+    }
+    else{
+      $page_title = $typed;
+    }
+    drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($page_title), PASS_THROUGH);
 
+    // render results
     if(isset($results)){
       // Load pager.
       // if ($results['result count'] > $page->options['per_page']) {

+ 50 - 2
materio_taxonomy.module

@@ -1,4 +1,4 @@
-<?php	
+<?php
 
 /**
  * Implements hook_permission().
@@ -18,7 +18,7 @@ function materio_taxonomy_permission() {
     'title' => t('access taxonomy terms page'),
     'description' => t(''),
   );
-  
+
   return $perms;
 }
 
@@ -26,4 +26,52 @@ function materio_taxonomy_menu_alter(&$items) {
   $items['taxonomy/term/%taxonomy_term']['access arguments'] = array('access taxonomy terms page');
   $items['taxonomy/term/%taxonomy_term/view']['access arguments'] = array('access taxonomy terms page');
   $items['taxonomy/term/%taxonomy_term/feed']['access arguments'] = array('access taxonomy terms page');
+}
+
+
+
+/**
+ * Implementation of hook_query_term_access_alter().
+ *
+ * debug de i18n_select_query_term_access_alter()
+ * qui filtre les terms par language mm pour les vocabulaires en mode localized.
+ * utile pour la recherche avancée de materio_search_api materio_search_api_advanced_search_form()
+ *
+ */
+function materio_taxonomy_query_term_access_alter(QueryAlterableInterface $query) {
+  // dsm($query, 'materio taxo query');
+  $conditions =& $query->conditions();
+
+  # roll over condition first time to determine i18n_voc_mode
+  $i18n_voc_mode = 0;
+  foreach ($conditions as $condition) {
+    if (is_array($condition)) {
+      // dsm($condition, 'conditon '.$condition['field']);
+      if($condition['field'] == 't.vid'){
+        $vid = $condition['value'];
+        $i18n_voc_mode = i18n_taxonomy_vocabulary_mode($vid);
+        // dsm($i18n_voc_mode, 'i18n_voc_mode');
+      }
+    }
+  }
+
+  # roll over conditions a second time to re-alter/fixe language selection
+  # i18n vocabulary mode is 1 for localized terms
+  if($i18n_voc_mode == 1){
+    foreach ($conditions as $index => $condition) {
+      if (is_array($condition)) {
+        // dsm($condition, 'conditon '.$condition['field']);
+        if($condition['field'] == 't.language' && $i18n_voc_mode == 1){
+          $l = array('und');
+          $ll = i18n_language_list();
+          // dsm($ll, 'list language');
+          foreach ($ll as $langcode => $langname) {
+            $l[] = $langcode;
+          }
+          $conditions[$index]['value'] = $l;
+        }
+      }
+    }
+  }
+
 }

+ 11 - 2
templates/materio-search-api-search-block.tpl.php

@@ -1,3 +1,12 @@
-<?php 
+<div class="inner">
 
-print render($searchform);
+  <?php
+
+  print render($searchform);
+  if(isset($advancedsearchform)){
+    print render($advancedsearchform);
+  }
+
+  ?>
+
+</div>