Implement drupal search module hooks
authorJakub Skoczen <jakub@indexdata.dk>
Thu, 24 Feb 2011 12:11:55 +0000 (13:11 +0100)
committerJakub Skoczen <jakub@indexdata.dk>
Thu, 24 Feb 2011 12:11:55 +0000 (13:11 +0100)
This is for the Ding D7 integration which uses standard drupal
hooks to integrate new search sources.

mkdru.module

index 9bc03b4..e477eab 100644 (file)
 function mkdru_node_info() {
   return array(
     'mkdru' => array(
-      'name' => t("Pazpar2 metasearch interface"),
-      'base' => 'mkdru',
+      'name'        => t("Pazpar2 metasearch interface"),
+      'base'        => 'mkdru',
       'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
     )
   );
 }
 
-function mkdru_ting_search_show($params) {
-   $path = drupal_get_path('module', 'mkdru');
+/**
+ * Implements hook_search_info()
+ */
+function mkdru_search_info() {
+  return array(
+    'title'               => 'Meta search',
+    'path'                => 'meta',
+    'conditions_callback' => 'mkdru_search_conditions_callback',
+  );
+}
+
+/**
+ * Implements hook_search_page()
+ */
+function mkdru_search_page($results) {
+  $output['prefix']['#markup'] = theme('mkdru_results');
+  $output['suffix']['#markup'] = '';
+  return $output;
+}
+
+/**
+ * Implements hook_ding_facetbrowser()
+ */
+function mkdru_ding_facetbrowser() {
+       $results             = new stdClass();
+  $results->facets     = array();
+  $results->show_empty = TRUE; # Show an empty facetbrowser block, even if search didn't return any results
+  return $results;
+}
+
+/**
+ * Search callback function that is invoked by search_view()
+ */
+function mkdru_search_conditions_callback($keys) {}
+
+/**
+ * Implement hook_search_execute()
+ */
+function mkdru_search_execute($keys = NULL, $conditions = NULL) {
+  $path = drupal_get_path('module', 'mkdru');
   // Include client library.
   drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js',
     array('type' => 'file', 'scope' => 'footer'));
@@ -27,11 +65,17 @@ function mkdru_ting_search_show($params) {
     array('type' => 'file', 'scope' => 'footer'));
   drupal_add_js($path . '/mkdru.client.js',
     array('type' => 'file', 'scope' => 'footer'));
-  $html = theme('mkdru_results');
-  drupal_add_js(array('mkdru' => 
-    array('use_sessions' => '1', 'query' => $params['keys']
-    )), 'setting');
-  return array("content" => $html);
+  drupal_add_js(array('mkdru' =>
+    array(
+      'use_sessions' => variable_get('use_sessions', '1'),
+      'pz2_path'     => variable_get('pz2_path', '/pazpar2/search.pz2'),
+      'sp_user'      => variable_get('sp_user', ''),
+      'sp_pass'      => variable_get('sp_pass', ''),
+      'query'        => $keys,
+    )
+  ), 'setting');
+
+  return array();
 }
 
 /**