new custom entity property (term become text)

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy 2013-04-24 20:50:35 +02:00
parent dfe36ba913
commit 13d6d3b95b
2 changed files with 86 additions and 44 deletions

View File

@ -136,21 +136,29 @@ 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'];
for ($i=1; $i <= 5 ; $i++) {
$properties['materio_search_api_taxonomy_term_'.$i] = array(
'type'=>'taxonomy_term',
'label'=> t('Main taxonomy term '.$i),
$properties['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_main_taxonomy_term_'.$i,
'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text',
);
}
// $properties['materio_search_api_taxonomy_term_'.$i] = array(
// 'type'=>'list<taxonomy_term>',
// 'label'=> t('Taxonomy term after 5 mains'),
// // 'query callback'=>'entity_metadata_table_query',
// 'getter callback'=>'materio_search_api_get_taxonomy_terms_after_5',
// );
// return $properties;
$properties['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(
'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'];
@ -162,33 +170,83 @@ function materio_search_api_entity_property_info_alter(&$info){
);
}
function materio_search_api_get_main_taxonomy_term_1($item){
function materio_search_api_get_onthologie_term_1_text($item){
// dsm($item, 'item');
// watchdog('materio solr', 'materio_search_api_get_taxonomy_term_1', array());
return materio_search_api_get_onto_term($item, 0);
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 0);
}
function materio_search_api_get_main_taxonomy_term_2($item){
function materio_search_api_get_onthologie_term_2_text($item){
// dsm($item, 'item');
return materio_search_api_get_onto_term($item, 1);
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 1);
}
function materio_search_api_get_main_taxonomy_term_3($item){
function materio_search_api_get_onthologie_term_3_text($item){
// dsm($item, 'item');
return materio_search_api_get_onto_term($item, 2);
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 2);
}
function materio_search_api_get_main_taxonomy_term_4($item){
function materio_search_api_get_onthologie_term_4_text($item){
// dsm($item, 'item');
return materio_search_api_get_onto_term($item, 3);
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 3);
}
function materio_search_api_get_main_taxonomy_term_5($item){
function materio_search_api_get_onthologie_term_5_text($item){
// dsm($item, 'item');
return materio_search_api_get_onto_term($item, 4);
return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 4);
}
function materio_search_api_get_onto_term($item, $delta){
function materio_search_api_get_taxonomy_terms_others_text($item){
// dsm($item, 'item');
$delta = 5;
$terms = array();
while( isset($item->field_onthologie['und'][$delta]) ){
$terms[] = materio_search_api_get_taxo_term_field_text($item, "field_onthologie", $delta);
$delta++;
}
return $terms;
}
function materio_search_api_get_taglibres_terms_text($item){
// dsm($item, 'item');
$delta = 0;
$terms = array();
while( isset($item->field_tags_libres['und'][$delta]) ){
$terms[] = materio_search_api_get_taxo_term_field_text($item, "field_tags_libres", $delta);
$delta++;
}
return $terms;
}
function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta){
// dsm($item, 'item');
// dsm($delta, 'delta');
if(isset($item->{$field_name}['und'][$delta])){
// print '** item **'."\n";
// print_r($item);
if(isset($item->field_onthologie['und'][$delta]))
return taxonomy_term_load($item->field_onthologie['und'][$delta]['tid']);
$term = taxonomy_term_load($item->{$field_name}['und'][$delta]['tid']);
// use entity metadata wrappers as they are SMART
$wrapper = entity_metadata_wrapper('taxonomy_term', $term);
// print '** wrapper **'."\n";
// print_r($wrapper);
// print "\n";
$keywords[] = $wrapper->language($item->language)->name_field->raw();
// print '** term_name **'."\n";
// print_r($term->name);
// print "\n";
// print_r($term_name);
// print "\n";
$synonymes = array();
foreach ($wrapper->language($item->language)->synonyms_synonym->value() as $index => $synonym) {
// print '** synonym **'."\n";
// print_r($synonym);
// print "\n";
$keywords[] = $synonym;
}
return implode(" ", $keywords);
}
return null;
}
@ -207,7 +265,6 @@ function company_term_property_country_get_props($term){
}
return null;
}
function company_get_tode_node($term){
if(module_exists('tode'))
if( $entitys = tode_get_nids_from_term($term))
@ -217,7 +274,6 @@ function company_get_tode_node($term){
return false;
}
function rip_tags($string) {
// ----- remove HTML TAGs -----
$string = preg_replace ('/<[^>]*>/', ' ', $string);

View File

@ -206,6 +206,9 @@ function materio_search_api_results_search(){
// dsm($filter, 'filter');
$query->filter($filter);
// $query->setOption('search_api_bypass_access', true);
$query->setOption('search_api_access_account', $user);
$results = $query->execute();
# in case of utilisateur search, run a real search to indicate how much items you could find
@ -233,23 +236,6 @@ function materio_search_api_results_search(){
// $results['results'] = $accessible_results;
// $results['result count'] = count($accessible_results);
# Load spellcheck.
// if (isset($results['search_api_spellcheck'])) {
// $ret['results']['#spellcheck'] = array(
// '#theme' => 'search_api_spellcheck',
// '#spellcheck' => $results['search_api_spellcheck'],
// // Let the theme function know where the key is stored by passing its arg
// // number. We can work this out from the number of args in the page path.
// '#options' => array(
// 'arg' => array(count(arg(NULL, $page->path))),
// ),
// '#prefix' => '<p class="search-api-spellcheck suggestion">',
// '#suffix' => '</p>',
// );
// }
if(user_access('use materio search api')){