SOLR : autocompletion accent & companie tranlation
accent : added a custom term propertie which duplicate the term name to index it without accent
companie : replaced the custom term propertie by a node (materiau) property
           which retrieve the companie info frome the tode node
			
			
This commit is contained in:
		@@ -99,6 +99,11 @@ function materio_search_api_access_search(){
 | 
				
			|||||||
  return user_access('use materio search api for breves') || user_access('use materio search api');
 | 
					  return user_access('use materio search api for breves') || user_access('use materio search api');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* - - - - - - - - - - - -  SOLR  - - - - - - - - - - - - 
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_search_api_data_type_info().
 | 
					 * Implements hook_search_api_data_type_info().
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -107,18 +112,20 @@ function materio_search_api_access_search(){
 | 
				
			|||||||
function materio_search_api_search_api_data_type_info() {
 | 
					function materio_search_api_search_api_data_type_info() {
 | 
				
			||||||
  return array(
 | 
					  return array(
 | 
				
			||||||
    'edge_n2_kw_text' => array(
 | 
					    'edge_n2_kw_text' => array(
 | 
				
			||||||
      'name' => t('Fulltext (w/ partial matching)'),
 | 
					      'name' => t('Fulltext (partial matching)'),
 | 
				
			||||||
      'fallback' => 'text',
 | 
					      'fallback' => 'text',
 | 
				
			||||||
      'prefix' => 'tem',
 | 
					      'prefix' => 'tem',
 | 
				
			||||||
      'always multiValued' => TRUE,
 | 
					      'always multiValued' => TRUE,
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
 | 
					    'edge_n2_kw_mapped_text' => array(
 | 
				
			||||||
 | 
					      'name' => t('Fulltext without accents (partial matching)'),
 | 
				
			||||||
 | 
					      'fallback' => 'text',
 | 
				
			||||||
 | 
					      'prefix' => 'temmap',
 | 
				
			||||||
 | 
					      'always multiValued' => TRUE,
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
* - - - - - - - - - - - -  SOLR  - - - - - - - - - - - - 
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_search_api_solr_dynamic_field_info().
 | 
					 * Implements hook_search_api_solr_dynamic_field_info().
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -130,20 +137,30 @@ function materio_search_api_search_api_solr_dynamic_field_info() {
 | 
				
			|||||||
      'prefix' => 'tem',
 | 
					      'prefix' => 'tem',
 | 
				
			||||||
      'always multiValued' => TRUE,
 | 
					      'always multiValued' => TRUE,
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
 | 
					    'edge_n2_kw_mapped_text' => array(
 | 
				
			||||||
 | 
					      'prefix' => 'temmap',
 | 
				
			||||||
 | 
					      'always multiValued' => TRUE,
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * hook_entity_property_info_alter().
 | 
					 * hook_entity_property_info_alter().
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * define own fields
 | 
				
			||||||
 | 
					 * - main taxonomy terms, the purpose is to be able to attribute differente boost on serach api depending on term order
 | 
				
			||||||
 | 
					 * - companies infos (address) : retrieve for materiau content type the companie info from the tode node
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function materio_search_api_entity_property_info_alter(&$info){
 | 
					function materio_search_api_entity_property_info_alter(&$info){
 | 
				
			||||||
  // dsm($info, 'hook_entity_property_info_alter | info');
 | 
					  // dsm($info, 'hook_entity_property_info_alter | info');
 | 
				
			||||||
  // watchdog('materio solr', 'materio_search_api_entity_property_info_alter', array());
 | 
					  // watchdog('materio solr', 'materio_search_api_entity_property_info_alter', array());
 | 
				
			||||||
  $properties = &$info['node']['properties'];
 | 
					  $node_props = &$info['node']['properties'];
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  for ($i=1; $i <= 5 ; $i++) { 
 | 
					  for ($i=1; $i <= 5 ; $i++) { 
 | 
				
			||||||
    $properties['materio_search_api_onthologie_term_'.$i.'_text'] = array(
 | 
					    $node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array(
 | 
				
			||||||
      'type'=>'text',
 | 
					      'type'=>'text',
 | 
				
			||||||
      'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
 | 
					      'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'),
 | 
				
			||||||
      // 'query callback'=>'entity_metadata_table_query',
 | 
					      // 'query callback'=>'entity_metadata_table_query',
 | 
				
			||||||
@@ -151,28 +168,42 @@ function materio_search_api_entity_property_info_alter(&$info){
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $properties['materio_search_api_onthologie_term_others_text'] = array(
 | 
					  $node_props['materio_search_api_onthologie_term_others_text'] = array(
 | 
				
			||||||
    'type'=>'list<text>',
 | 
					    'type'=>'list<text>',
 | 
				
			||||||
    'label'=> t('Others onthologie terms as text (+ synonyms)'),
 | 
					    'label'=> t('Others onthologie terms as text (+ synonyms)'),
 | 
				
			||||||
    // 'query callback'=>'entity_metadata_table_query',
 | 
					    // 'query callback'=>'entity_metadata_table_query',
 | 
				
			||||||
    'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
 | 
					    'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text',
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $properties['materio_search_api_taglibres_text'] = array(
 | 
					  $node_props['materio_search_api_taglibres_text'] = array(
 | 
				
			||||||
    'type'=>'list<text>',
 | 
					    'type'=>'list<text>',
 | 
				
			||||||
    'label'=> t('Tag libres terms as text (+ synonyms)'),
 | 
					    'label'=> t('Tag libres terms as text (+ synonyms)'),
 | 
				
			||||||
    // 'query callback'=>'entity_metadata_table_query',
 | 
					    // 'query callback'=>'entity_metadata_table_query',
 | 
				
			||||||
    'getter callback'=>'materio_search_api_get_taglibres_terms_text',
 | 
					    'getter callback'=>'materio_search_api_get_taglibres_terms_text',
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $company_term_props = &$info['taxonomy_term']['bundles']['company']['properties'];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $company_term_props['country'] = array(
 | 
					
 | 
				
			||||||
    'label' => t("Country"), 
 | 
					  $node_materiau_props = &$info['node']['bundles']['materiau']['properties'];
 | 
				
			||||||
    'description' => t("Company's Country get from tode node."), 
 | 
					
 | 
				
			||||||
    'type' => 'text', 
 | 
					  $node_materiau_props['materio_search_api_node_propertie_companie'] = array(
 | 
				
			||||||
    'getter callback' => 'company_term_property_country_get_props',
 | 
					    'type'=>'list<text>',
 | 
				
			||||||
 | 
					    'label'=> t('Manufacturers and distributors companies localised (dont addresse)'),
 | 
				
			||||||
 | 
					    // 'query callback'=>'entity_metadata_table_query',
 | 
				
			||||||
 | 
					    'getter callback'=>'materio_search_api_get_companies',
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $term_props = &$info['taxonomy_term']['properties'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $term_props['materio_search_api_term_property_dup_name'] = array(
 | 
				
			||||||
 | 
					    'label' => t("Term name field dup"), 
 | 
				
			||||||
 | 
					    'description' => t("Duplicate the term name field to apply different filter in solr (remove accents for instance)"), 
 | 
				
			||||||
 | 
					    'type' => 'text', 
 | 
				
			||||||
 | 
					    'getter callback' => 'term_property_dup_name',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function materio_search_api_get_onthologie_term_1_text($item){
 | 
					function materio_search_api_get_onthologie_term_1_text($item){
 | 
				
			||||||
@@ -256,20 +287,35 @@ function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta)
 | 
				
			|||||||
  return null;
 | 
					  return null;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function materio_search_api_node_propertie_companie($item){
 | 
				
			||||||
 | 
					  // dsm($item, '$item');
 | 
				
			||||||
 | 
					  $lang = "fr";//$item->language;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
function company_term_property_country_get_props($term){
 | 
					  $languages = language_list();
 | 
				
			||||||
  // dsm($term, 'company_term_property_country_get_props : term');
 | 
					  global $language;
 | 
				
			||||||
  if( $node = company_get_tode_node($term) ){
 | 
					  $language = $languages[$lang];
 | 
				
			||||||
    // $field_values = field_get_items('node',$node,'field_public_address');
 | 
					 | 
				
			||||||
    // dsm($field_values, 'field_values');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $output = rip_tags(render(field_view_field('node',$node,'field_public_address')));
 | 
					  $cies = array();
 | 
				
			||||||
    // dsm($output, 'output');
 | 
					  $cie_fields = array("field_company_fab", "field_company_distrib");
 | 
				
			||||||
    
 | 
					  foreach ($cie_fields as $cie_field_name) {
 | 
				
			||||||
    return $output;
 | 
					    $delta = 0;
 | 
				
			||||||
 | 
					    while( isset($item->{$cie_field_name}['und'][$delta]) ){
 | 
				
			||||||
 | 
					      $tid = $item->{$cie_field_name}['und'][$delta]['tid'];
 | 
				
			||||||
 | 
					      $cie_term =  taxonomy_term_load($tid);
 | 
				
			||||||
 | 
					      if($cie_node = company_get_tode_node($cie_term)){
 | 
				
			||||||
 | 
					        $cie_node->language = $lang;
 | 
				
			||||||
 | 
					        $cie_view = node_view($cie_node, "full", $lang);
 | 
				
			||||||
 | 
					        $cie_rendered = rip_tags(drupal_render($cie_view));
 | 
				
			||||||
 | 
					        // dsm($cie_rendered, 'cie_rendered');
 | 
				
			||||||
 | 
					        $cies[] = $cie_rendered;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
  return null;
 | 
					      $delta++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  return $cies;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function company_get_tode_node($term){
 | 
					function company_get_tode_node($term){
 | 
				
			||||||
  if(module_exists('tode'))
 | 
					  if(module_exists('tode'))
 | 
				
			||||||
    if( $entitys = tode_get_nids_from_term($term))
 | 
					    if( $entitys = tode_get_nids_from_term($term))
 | 
				
			||||||
@@ -279,6 +325,7 @@ function company_get_tode_node($term){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  return false;
 | 
					  return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function rip_tags($string) { 
 | 
					function rip_tags($string) { 
 | 
				
			||||||
  // ----- remove HTML TAGs ----- 
 | 
					  // ----- remove HTML TAGs ----- 
 | 
				
			||||||
  $string = preg_replace ('/<[^>]*>/', ' ', $string); 
 | 
					  $string = preg_replace ('/<[^>]*>/', ' ', $string); 
 | 
				
			||||||
@@ -303,6 +350,20 @@ function rip_tags($string) {
 | 
				
			|||||||
  return $string;
 | 
					  return $string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function materio_search_api_term_property_dup_name($term){
 | 
				
			||||||
 | 
					  $lang = $term->language;
 | 
				
			||||||
 | 
					  return $term->name_field[$lang][0]['value'];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  - - -- - - - - - -  blocks - - - - - - - - - - - 
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_block_info().
 | 
					 * Implements hook_block_info().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user