diff ismi_ext/ismi_ext.module @ 0:124ef8f3b22d

initial
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Fri, 27 Mar 2015 19:21:42 +0100
parents
children 3585573999b6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ismi_ext/ismi_ext.module	Fri Mar 27 19:21:42 2015 +0100
@@ -0,0 +1,127 @@
+<?php
+
+// alter indexing
+
+function ismi_ext_apachesolr_index_documents_alter($documents, $entity, $entity_type, $env_id){
+  // 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);
+
+}
+