Index: solr/project_solr.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/solr/project_solr.module,v retrieving revision 1.61 diff -U3 -r1.61 project_solr.module --- solr/project_solr.module 11 Aug 2009 21:40:08 -0000 1.61 +++ solr/project_solr.module 6 Sep 2009 01:39:07 -0000 @@ -174,24 +174,13 @@ return theme('item_list', $items); } -function project_solr_browse_page($term_name) { +/** + * The actual searching is done here. + */ +function project_solr_browse_search($parent_term = '') { try { - $output = ''; - - $parent_term = db_fetch_object(db_query("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) = LOWER('%s')", _project_get_vid(), $term_name)); - - if (!$parent_term) { - // XXX: this is the Drupal 5 way... - return drupal_not_found(); - } - drupal_set_title(check_plain($parent_term->name)); - if (!empty($parent_term->description)) { - $output .= theme('project_type_description', $parent_term); - } - $text_query = isset($_GET['text']) ? $_GET['text'] : ''; $filters = isset($_GET['filters']) ? $_GET['filters'] : ''; - $sort = isset($_GET['solrsort']) ? check_plain($_GET['solrsort']) : ''; // Validate sort parameter @@ -230,7 +219,7 @@ // This hook allows modules to modify the query and params objects. apachesolr_modify_query($query, $params, 'project_solr'); if (!$query) { - return array(); + return NULL; } // Force sort to be by the corresponding core compatibility if filtered. @@ -245,7 +234,9 @@ // filters for the query -- project nodes of the given top-level type that // have releases (if project_release is enabled). $fq[] = 'type:project_project'; - $fq[] = 'im_vid_'. _project_get_vid() .':'. $parent_term->tid; + if (is_object($parent_term)) { + $fq[] = 'im_vid_'. _project_get_vid() .':'. $parent_term->tid; + } if (module_exists('project_release')) { $fq[] = 'is_project_has_releases:1'; } @@ -255,35 +246,61 @@ // The response is cached so that it is accessible to the blocks and anything // else that needs it beyond the initial search. - $total = $response->response->numFound; - - project_solr_response_cache(array($query, $response, $parent_term)); - - // Set breadcrumb - $breadcrumb = menu_get_active_breadcrumb(); - drupal_set_breadcrumb($breadcrumb); - - $output .= '
'; - pager_query("SELECT %d", $params['rows'], 0, NULL, $total); - if ($total > 0) { - foreach ($response->response->docs as $doc) { - $doc->created = strtotime($doc->created); - $doc->changed = strtotime($doc->changed); - $output .= project_solr_render_search_result($doc); - } - } - else { - $output .= t('No projects found in this category.'); + if (is_object($parent_term) { + project_solr_response_cache(array($query, $response, $parent_term)); } - $output .= '
'; // id="project-overview" - $output .= theme('pager', NULL, $params['rows'], 0); + return $response; } catch (Exception $e) { watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR); apachesolr_failure(t('Solr search'), is_null($query) ? $keys : $query->get_query_basic()); + return NULL; + } +} + +/** + * Page for browsing/searching of modules. + */ +function project_solr_browse_page($term_name) { + $output = ''; + + $parent_term = db_fetch_object(db_query("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) = LOWER('%s')", _project_get_vid(), $term_name)); + if (!$parent_term) { + // XXX: this is the Drupal 5 way... + return drupal_not_found(); + } + drupal_set_title(check_plain($parent_term->name)); + if (!empty($parent_term->description)) { + $output .= theme('project_type_description', $parent_term); + } + + $response = project_solr_browse_search($parent_term); + if ($response == NULL) { + return $output; + } + + $total = $response->response->numFound; + + // Set breadcrumb + $breadcrumb = menu_get_active_breadcrumb(); + drupal_set_breadcrumb($breadcrumb); + + $output .= '
'; + pager_query("SELECT %d", variable_get('apachesolr_rows', 10), 0, NULL, $total); + if ($total > 0) { + foreach ($response->response->docs as $doc) { + $doc->created = strtotime($doc->created); + $doc->changed = strtotime($doc->changed); + $output .= project_solr_render_search_result($doc); + } + } + else { + $output .= t('No projects found in this category.'); } + $output .= '
'; // id="project-overview" + $output .= theme('pager', NULL, $params['rows'], 0); return $output; }