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:
Bachir Soussi Chiadmi 2014-02-19 16:59:29 +01:00
parent 3757a19ce7
commit 6ccf2ddb91

View File

@ -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');
}
/**
* - - - - - - - - - - - - SOLR - - - - - - - - - - - -
*/
/**
* 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() {
return array(
'edge_n2_kw_text' => array(
'name' => t('Fulltext (w/ partial matching)'),
'name' => t('Fulltext (partial matching)'),
'fallback' => 'text',
'prefix' => 'tem',
'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().
*
@ -130,20 +137,30 @@ function materio_search_api_search_api_solr_dynamic_field_info() {
'prefix' => 'tem',
'always multiValued' => TRUE,
),
'edge_n2_kw_mapped_text' => array(
'prefix' => 'temmap',
'always multiValued' => TRUE,
),
);
}
/**
* 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){
// dsm($info, 'hook_entity_property_info_alter | info');
// 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++) {
$properties['materio_search_api_onthologie_term_'.$i.'_text'] = array(
$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',
@ -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>',
'label'=> t('Others onthologie terms as text (+ synonyms)'),
// 'query callback'=>'entity_metadata_table_query',
'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>',
'label'=> t('Tag libres terms as text (+ synonyms)'),
// 'query callback'=>'entity_metadata_table_query',
'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"),
'description' => t("Company's Country get from tode node."),
'type' => 'text',
'getter callback' => 'company_term_property_country_get_props',
$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_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){
@ -256,20 +287,35 @@ function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta)
return null;
}
function materio_search_api_node_propertie_companie($item){
// dsm($item, '$item');
$lang = "fr";//$item->language;
$languages = language_list();
global $language;
$language = $languages[$lang];
function company_term_property_country_get_props($term){
// dsm($term, 'company_term_property_country_get_props : term');
if( $node = company_get_tode_node($term) ){
// $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')));
// dsm($output, 'output');
return $output;
$cies = array();
$cie_fields = array("field_company_fab", "field_company_distrib");
foreach ($cie_fields as $cie_field_name) {
$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;
}
$delta++;
}
}
return null;
return $cies;
}
function company_get_tode_node($term){
if(module_exists('tode'))
if( $entitys = tode_get_nids_from_term($term))
@ -279,6 +325,7 @@ function company_get_tode_node($term){
return false;
}
function rip_tags($string) {
// ----- remove HTML TAGs -----
$string = preg_replace ('/<[^>]*>/', ' ', $string);
@ -303,6 +350,20 @@ function rip_tags($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().
*/