Index: contrib/apachesolr_book/apachesolr_book.info
===================================================================
RCS file: contrib/apachesolr_book/apachesolr_book.info
diff -N contrib/apachesolr_book/apachesolr_book.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/apachesolr_book/apachesolr_book.info	8 Apr 2009 22:49:47 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = ApacheSolr Book
+description = Integrates Book Module and ApacheSolr
+dependencies[] = apachesolr
+dependencies[] = book
+package = Apache Solr
+core = "6.x"
Index: contrib/apachesolr_book/apachesolr_book.module
===================================================================
RCS file: contrib/apachesolr_book/apachesolr_book.module
diff -N contrib/apachesolr_book/apachesolr_book.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/apachesolr_book/apachesolr_book.module	8 Apr 2009 22:49:47 -0000
@@ -0,0 +1,88 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ *   Integrates Book info with Apache Solr search application.
+ */
+
+/**
+ * Implementation of hook_apachesolr_update_index().
+ */
+function apachesolr_book_apachesolr_update_index(&$document, $node) {
+  if (!empty($node->book['bid'])) {
+    $document->is_book_bid = $node->book['bid'];
+  }
+}
+
+/**
+ * Implementation of hook_apachesolr_modify_query().
+ */
+function apachesolr_book_apachesolr_modify_query(&$query, &$params, $caller) {
+  if ($caller == 'apachesolr_search') {
+    $params['fl'] .= ',is_book_bid';
+  }
+}
+
+/**
+ * Implementation of hook_apachesolr_facets().
+ */
+function apachesolr_book_apachesolr_facets() {
+  $facets['is_book_bid'] = array(
+    'info' => t('Apache Solr Book: Filter by Book'),
+    'facet_field' => 'is_book_bid',
+  );
+  return $facets;
+}
+
+/**
+ * Implementation of hook_block().
+ */
+function apachesolr_book_block($op = 'list', $delta = 0, $edit = array()) {
+  switch ($op) {
+    case 'list':
+      $enabled_facets = apachesolr_get_enabled_facets('apachesolr_book');
+      $facets = apachesolr_book_apachesolr_facets();
+      // Add the blocks
+      $blocks = array();
+      foreach ($enabled_facets as $delta => $facet_field) {
+        $blocks[$delta] = $facets[$delta] + array('cache' => BLOCK_CACHE_PER_PAGE,);
+      }
+      return $blocks;
+
+    case 'view':
+      if (apachesolr_has_searched()) {
+        if ($delta != 'is_book_bid') {
+          return;
+        }
+        
+        $response = apachesolr_static_response_cache();
+        if (empty($response)) {
+          return;
+        }
+        $query = apachesolr_current_query();
+
+        return apachesolr_facet_block($response, $query, 'apachesolr_book', $delta, $delta, t('Filter by Book'), 'apachesolr_book_book_name');
+      }
+      break;
+
+    case 'configure':
+      return apachesolr_facetcount_form($delta);
+    case 'save':
+      apachesolr_facetcount_save($delta, $edit);
+      break;
+  }
+}
+
+/**
+ * Callback function for the 'Filter by book' facet block.
+ */
+function apachesolr_book_book_name($facet) {
+  if ($facet == 0) {
+    return t('No book');
+  }
+
+  $sql = 'SELECT title FROM {node} WHERE nid = %d';
+  return db_result(db_query($sql, $facet));
+}
+
