Explorar el Código

entity props address for indexing fixed

Signed-off-by: bachy <git@g-u-i.net>
bachy hace 12 años
padre
commit
779d42d9bb
Se han modificado 1 ficheros con 42 adiciones y 36 borrados
  1. 42 36
      materio_search_api.module

+ 42 - 36
materio_search_api.module

@@ -183,57 +183,63 @@ function materio_search_api_get_main_taxonomy_term_5($item){
   // dsm($item, 'item');
   return materio_search_api_get_onto_term($item, 4);
 }
+function materio_search_api_get_onto_term($item, $delta){
+  // dsm($item, 'item');
+  // dsm($delta, 'delta');
+
+  if(isset($item->field_onthologie['und'][$delta]))
+    return taxonomy_term_load($item->field_onthologie['und'][$delta]['tid']);
+
+  return null;
+}
+
 
 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_adress');
-    $address = '';
-    foreach ($field_values as $value) {
-      $address .= $value['value'];
-    }
-    return $address;
+    // $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;
   }
   return null;
 }
 
 function company_get_tode_node($term){
   if(module_exists('tode'))
-    if( $entitys = tode_get_nids_from_term($term) && isset($entitys['node']) )
-      foreach ($entitys['node'] as $nid => $n)
-        return node_load($nid);
+    if( $entitys = tode_get_nids_from_term($term))
+      if(isset($entitys['node']))
+        foreach ($entitys['node'] as $nid => $n)
+          return node_load($nid);
 
   return false;
 }
 
+function rip_tags($string) { 
+  // ----- remove HTML TAGs ----- 
+  $string = preg_replace ('/<[^>]*>/', ' ', $string); 
+  
+  // ----- remove control characters ----- 
+  $string = str_replace("\r", '', $string);    // --- replace with empty space
+  $string = str_replace("\n", ' ', $string);   // --- replace with space
+  $string = str_replace("\t", ' ', $string);   // --- replace with space
+  
+  // $string = str_replace("&nbsp;", ' ', $string);   // --- replace with space
+  // $string = str_replace("&#039;", '\'', $string);   // --- replace with space
 
-// function materio_search_api_get_taxonomy_terms_after_5($item){
-//   // dsm($item, 'item');
-//   watchdog('materio solr', 'materio_search_api_get_taxonomy_terms_after_5', array());
-//   if(isset($item->field_onthologie['und'])){
-//     $terms = array();
-//     foreach ($item->field_onthologie['und'] as $delta => $value) {
-//       if($delta>4){
-//         $tid = $item->field_onthologie['und'][$delta]['tid'];
-//         $terms[] = taxonomy_term_load($tid);
-//         // $terms[] = $item->field_onthologie['und'][$delta];
-//         // $terms[] = $value['tid'];
-//         watchdog('materio solr', 'tid is '.$tid, array());
-//       }
-//     }
-
-//     return $terms;
-//   }
-//   return null;
-// }
-
-function materio_search_api_get_onto_term($item, $delta){
-  // dsm($item, 'item');
-  // dsm($delta, 'delta');
-
-  if(isset($item->field_onthologie['und'][$delta]))
-    return taxonomy_term_load($item->field_onthologie['und'][$delta]['tid']);
+  // ----- remove multiple spaces ----- 
+  $string = trim(preg_replace('/ {2,}/', ' ', $string));
 
-  return null;
+  // ----- remove html entities
+  preg_match_all('/&[^;]+;/', $string, $entities);
+  foreach ($entities[0] as $entity) {
+    $string = str_replace($entity, mb_convert_encoding($entity, 'UTF-8', 'HTML-ENTITIES'), $string);
+  }
+  
+  return $string;
 }
 
 /**