view ismi_ext/ismi_ext.module @ 22:3585573999b6

fix error messages when indexing.
author casties
date Wed, 23 Sep 2015 11:54:22 +0200
parents 124ef8f3b22d
children
line wrap: on
line source

<?php

// alter indexing

function ismi_ext_apachesolr_index_documents_alter($documents, $entity, $entity_type, $env_id) {
	
	if (!property_exists($entity, "field_attribute")) {
		// not an openmind_entity
		return;
	}
	
	// hole entities die sich auf diese beziehen

    $attributes = $entity->field_attribute[LANGUAGE_NONE];

    //TODO nimme nur das erste, kann es mehr geben?
    if (isset ($documents[0])){
      foreach ($attributes as $attribute){

        #attributes als felder in solr
        $txt = $attribute['ov'];

        $txt_chunks = str_split($txt,$split_length=10000); # teile den String falls zu lang in chunks


        foreach ($txt_chunks as $txt_chunk){
          $documents[0]->addField("attr_" . $attribute['name'],$txt_chunk);
          $documents[0]->addField("attrtext_" . $attribute['name'],$txt_chunk);
        }

      }
    }

    #relations als felder in solr

    $rels = relation_query($entity_type, $entity->nid)->execute();

    foreach($rels as $rel){


      $rel_type = $rel->relation_type;

      $relation = relation_load($rel->rid);

      $endpoints = relation_get_endpoints($relation);


      //store only the endpoint which is differes from the current _entity


      $nodes = $endpoints['node'];



      foreach ($nodes as $nid => $node){
        if ($nid != $entity->nid){
          $title = $node->title;
        }
      }

      //TODO nimme nur das erste, kann es mehr geben?
      if (isset ($documents[0])){

        $documents[0]->addField("rel_" . $rel_type,$title);

      }
    }


}



function ismi_ext_facetapi_facet_info($searcher_info) {
   $facets = array();

   $facets['entityType'] = array(
       'label' => t('Entity Types'),
       'description' => t('Filter by Entity Type'),
       'field' => 'sm_vid_openmind_types',
       //'map callback' => 'facetapi_map_language',
       //'values callback' => 'facetapi_callback_language_values',
       'facet mincount allowed' => TRUE,
       'dependency plugins' => array('bundle', 'role'),
   );

   $facets['explicit'] = array(
       'label' => t('Explicit'),
       'description' => t('Filter by Explicit'),
       'field' => 'attrtext_explicit',
       //'map callback' => 'facetapi_map_language',
       //'values callback' => 'facetapi_callback_language_values',
       'facet mincount allowed' => TRUE,
       'dependency plugins' => array('bundle', 'role'),
   );

   $facets['incipit'] = array(
       'label' => t('Incipit'),
       'description' => t('Filter by Incipit'),
       'field' => 'attrtext_incipit',
       //'map callback' => 'ismi_ext_map_incipit',
       //'values callback' => 'facetapi_callback_language_values',
       'facet mincount allowed' => TRUE,
       'dependency plugins' => array('bundle', 'role'),
   );

   $facets['persons'] = array(
       'label' => t('Persons (created)'),
       'description' => t('Filter by Persons (was_created_by)'),
       'field' => 'rel_was_created_by',
       //'map callback' => 'facetapi_map_language',
       //'values callback' => 'facetapi_callback_language_values',
       'facet mincount allowed' => TRUE,
       'dependency plugins' => array('bundle', 'role'),
   );

  return $facets;
}

function ismi_ext_theme_registry_alter(&$theme_registry){
   $link_active = $theme_registry['facetapi_link_inactive'];
   $link_active['preprocess_functions'][]='ismi_ext_process_link';
   $theme_registry['facetapi_link_active']=$link_active;


}

function imi_ext_process_link(&$value){
  dpm($value);

}