? SolrPhpClient ? underscores.patch Index: apachesolr.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v retrieving revision 1.1.2.12.2.155.2.27 diff -u -p -r1.1.2.12.2.155.2.27 apachesolr.module --- apachesolr.module 17 Sep 2009 17:14:06 -0000 1.1.2.12.2.155.2.27 +++ apachesolr.module 17 Sep 2009 21:26:52 -0000 @@ -383,11 +383,17 @@ function apachesolr_index_nodes($rows, $ // Build node. Set reset = TRUE to avoid static caching of all nodes that get indexed. if ($node = node_load($row->nid, NULL, TRUE)) { foreach ($callbacks as $callback) { + // The callback can either return a $document or an array of $documents. $documents[] = $callback($node, $namespace); } } } + // Flatten $documents + $tmp = (object) array('a' => array()); + array_walk_recursive($documents, create_function('&$v, $k, &$t', '$t->a[] = $v;'), $tmp); + $documents = $tmp->a; + if (count($documents)) { try { watchdog('Apache Solr', 'Adding @count documents.', array('@count' => count($documents))); Index: apachesolr_search.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v retrieving revision 1.1.2.6.2.111.2.22 diff -u -p -r1.1.2.6.2.111.2.22 apachesolr_search.module --- apachesolr_search.module 17 Sep 2009 17:14:06 -0000 1.1.2.6.2.111.2.22 +++ apachesolr_search.module 17 Sep 2009 21:26:52 -0000 @@ -171,7 +171,7 @@ function apachesolr_search_view($type = return module_invoke($type, 'search_page', $content); } else { - return theme('search_results', $content, $type); + return drupal_get_form('search_form', NULL, $keys, $type) . theme('search_results', $content, $type); } } @@ -362,7 +362,7 @@ function apachesolr_search_execute($keys apachesolr_has_searched(TRUE); // Add search terms and filters onto the breadcrumb. drupal_set_breadcrumb(array_merge(menu_get_active_breadcrumb(), $query->get_breadcrumb())); - return apachesolr_process_response($response, $query, $params); + return apachesolr_search_process_response($response, $query, $params); } function apachesolr_search_basic_params($query) { @@ -532,7 +532,7 @@ function apachesolr_search_add_boost_par } } -function apachesolr_process_response($response, $query, $params) { +function apachesolr_search_process_response($response, $query, $params) { $results = array(); // We default to getting snippets from the body. $hl_fl = is_null($params['hl.fl']) ? 'body' : $params['hl.fl']; @@ -558,10 +558,10 @@ function apachesolr_process_response($re } $doc->created = strtotime($doc->created); $doc->changed = strtotime($doc->changed); - // Allow modules to alter each document. - drupal_alter('apachesolr_search_result', $doc); - // Copy code from comment_nodeapi(). - $extra[] = format_plural($doc->comment_count, '1 comment', '@count comments'); + $extra = array(); + $extra['comments'] = format_plural($doc->comment_count, '1 comment', '@count comments'); + // Allow modules to alter each document and its extra information. + drupal_alter('apachesolr_search_result', $doc, $extra); $results[] = array( 'link' => url($doc->path), 'type' => apachesolr_search_get_type($doc->type), @@ -871,7 +871,12 @@ function apachesolr_search_get_username( * Callback function for the 'Filter by type' facet block. */ function apachesolr_search_get_type($facet) { - $type = node_get_types('name', $facet); + if ($type = node_get_types('name', $facet)) { + + } + else if ($facet == 'comment') { + $type = t('Comment'); + } // A disabled or missing node type returns FALSE. return ($type === FALSE) ? $facet : $type; } Index: contrib/apachesolr_commentsearch/apachesolr_commentsearch.info =================================================================== RCS file: contrib/apachesolr_commentsearch/apachesolr_commentsearch.info diff -N contrib/apachesolr_commentsearch/apachesolr_commentsearch.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ contrib/apachesolr_commentsearch/apachesolr_commentsearch.info 17 Sep 2009 21:26:52 -0000 @@ -0,0 +1,7 @@ +; $Id: apachesolr.info,v 1.1.2.1.2.8 2009/06/04 13:33:36 robertDouglass Exp $ +name = Apache Solr comment search +description = Treats comments as a content type allowing you to search them separately. +dependencies[] = apachesolr_search +package = Apache Solr +core = "6.x" +php = 5.1.4 Index: contrib/apachesolr_commentsearch/apachesolr_commentsearch.install =================================================================== RCS file: contrib/apachesolr_commentsearch/apachesolr_commentsearch.install diff -N contrib/apachesolr_commentsearch/apachesolr_commentsearch.install --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ contrib/apachesolr_commentsearch/apachesolr_commentsearch.install 17 Sep 2009 21:26:52 -0000 @@ -0,0 +1,23 @@ +nid); + while ($comment = db_fetch_object($result)) { + $text = check_markup($comment->comment, $comment->format, FALSE); + $text = apachesolr_strip_ctl_chars($text); + + $document = new Apache_Solr_Document(); + $document->id = apachesolr_document_id($comment->cid, 'comment'); + $document->is_cid = $comment->cid; + $document->site = url(NULL, array('absolute' => TRUE)); + $document->hash = apachesolr_site_hash(); + $document->nid = $comment->nid; + $document->uid = $comment->uid; + $document->title = apachesolr_clean_text($comment->subject); + $document->status = $node->status; + if (!empty($node->language)) { + $document->language = $node->language; + } + $document->body = apachesolr_clean_text($text); + $document->type = 'comment'; + $document->type_name = 'Comment'; + $document->created = apachesolr_date_iso($node->created); + $document->changed = apachesolr_date_iso($node->changed); + $last_change = (isset($node->last_comment_timestamp) && $node->last_comment_timestamp > $node->changed) ? $node->last_comment_timestamp : $node->changed; + $document->last_comment_or_change = apachesolr_date_iso($last_change); + $document->name = apachesolr_strip_ctl_chars($comment->name); + $path = "node/{$node->nid}"; + $document->url = url($path, array('absolute' => TRUE, 'fragment' => "comment-{$comment->cid}")); + $document->path = $path; + $documents[] = $document; + } + return $documents; +} + +function apachesolr_commentsearch_apachesolr_modify_query(&$query, &$params, $caller) { + $params['fl'] .= ',is_cid'; +} + +function apachesolr_commentsearch_apachesolr_process_results(&$results) { + foreach ($results as $pos => $result) { + if (isset($results[$pos]['extra']['comments'])) { + unset($results[$pos]['extra']['comments']); + unset($results[$pos]['extra']['cid']); + } + } +} + +function apachesolr_commentsearch_apachesolr_search_result_alter(&$doc, &$extra) { + if ($doc->type == 'comment') { + $nid = $doc->nid; + $extra['cid'] = $doc->is_cid; + $node = node_load($nid); + $query = apachesolr_commentsearch_page_count(comment_num_all($nid), $node, $doc->is_cid); + $doc->path = url($doc->path, array('absolute' => TRUE, 'fragment' => "comment-{$doc->is_cid}", 'query' => $query)); + } +} + +function apachesolr_commentsearch_apachesolr_theme_breadcrumb_alter(&$breadcrumb_name) { + $breadcrumb_name = 'apachesolr_commentsearch_breadcrumb_type'; +} + +/** + * Return the human readable text for a content type. + */ +function theme_apachesolr_commentsearch_breadcrumb_type($field) { + $type = $field['#value']; + if ($type == 'comment') { + return t('Comment'); + } + return node_get_types('name', $type); +} + +/** + * Implementation of hook_theme(). + */ +function apachesolr_commentsearch_theme() { + return array( + 'apachesolr_commentsearch_breadcrumb_type' => array( + 'arguments' => array('field' => NULL), + ), + ); +} + +/** + * Calculate page number for first new comment. + * + * @param $num_comments + * Number of comments. + * @param $node + * The node to whom the comments belong. + * @param $cid + * The cid of the comment we're looking for. + * @return + * "page=X" if the page number is greater than zero; NULL otherwise. + */ +function apachesolr_commentsearch_page_count($num_comments, $node, $cid) { + $comments_per_page = _comment_get_display_setting('comments_per_page', $node); + $mode = _comment_get_display_setting('mode', $node); + $order = _comment_get_display_setting('sort', $node); + $pagenum = NULL; + $flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED)); + if ($num_comments <= $comments_per_page || ($flat && $order == COMMENT_ORDER_NEWEST_FIRST)) { + // Only one page of comments or flat forum and newest first. + // First new comment will always be on first page. + $pageno = 0; + } + else { + if ($flat) { + // Flat comments and oldest first. + $count = $num_comments; + } + else { + // Threaded comments. See the documentation for comment_render(). + if ($order == COMMENT_ORDER_NEWEST_FIRST) { + // Newest first: find the last thread with new comment + $result = db_query('(SELECT cid, thread FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC) ORDER BY thread', $node->nid); + } + else { + // Oldest first: find the first thread with new comment + $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))', $node->nid); + } + $count = 0; + while ($row = db_fetch_object($result)) { + $count++; + if ($row->cid == $cid) { + break; + } + } + } + $pageno = $count / $comments_per_page; + } + if ($pageno >= 1) { + $pagenum = "page=". intval($pageno); + } + return $pagenum; +}