view ismi_ext/ismi_ext.module @ 41:5b3cd0b66b30

fix bug with multiple-saved nodes.
author casties
date Wed, 02 Nov 2016 16:56:27 +0100
parents 3585573999b6
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);

}