--- apachesolr_search-justfacets.module 2009-05-26 09:18:35.944644962 -0500 +++ apachesolr_search.module 2009-05-26 09:20:31.773948635 -0500 @@ -134,12 +134,90 @@ else { $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg())); } + } else { + // Show search form and browse-by blocks + $browse_by = apachesolr_search_browse(); + return drupal_get_form('search_form', NULL, $keys, $type) . $browse_by; } // Construct the search form. return drupal_get_form('search_form', NULL, $keys, $type) . $results; } /** + * Copying parts over from apachesolr_search_search() to get a facet listing of all enabled facets + */ +function apachesolr_search_browse() { + // No keys nor filters, so show the the browse-by blocks + $query = apachesolr_drupal_query('', '', '', 'search/' . arg(1)); + $params = array( + 'rows' => 0, + 'facet' => 'true', + 'facet.mincount' => 1, + 'facet.sort' => 'true' + ); + foreach (apachesolr_get_enabled_facets() as $module => $module_facets) { + foreach($module_facets as $delta => $facet_field) { + // TODO: generalize handling of date and range facets. + if ($module == 'apachesolr_search' && ($facet_field == 'created' || $facet_field == 'changed')) { + list($start, $end, $gap) = apachesolr_search_date_range($query, $facet_field); + if ($gap) { + $params['facet.date'][] = $facet_field; + $params['f.'. $facet_field .'.facet.date.start'] = $start; + $params['f.'. $facet_field .'.facet.date.end'] = $end; + $params['f.'. $facet_field .'.facet.date.gap'] = $gap; + } + } + else { + $params['facet.field'][] = $facet_field; + // Facet limits + if (isset($facet_query_limits[$module][$delta])) { + $params['f.' . $facet_field . '.facet.limit'] = $facet_query_limits[$module][$delta]; + } + // Facet missing + if (!empty($facet_missing[$module][$delta])) { + $params['f.' . $facet_field . '.facet.missing'] = 'true'; + } + } + } + } + if (!empty($params['facet.field'])) { + // Add a default limit for fields where no limit was set. + $params['facet.limit'] = variable_get('apachesolr_facet_query_limit_default', 20); + } + // This is the object that does the communication with the solr server. + $solr = apachesolr_get_solr(); + + // Cache the built query. Since all the built queries go through + // this process, all the hook_invocations will happen later + apachesolr_current_query($query); + $response = $solr->search($query->get_query_basic(), $params['start'], $params['rows'], $params); + apachesolr_static_response_cache($response); + apachesolr_has_searched(TRUE); + $result = ""; + + // Get blocks for all enabled filters + foreach (apachesolr_get_enabled_facets() as $module => $module_facets) { + foreach($module_facets as $delta => $facet_field) { + if ($delta == "currentsearch") { + continue; + } + $blocks[$facet_field] = (object)module_invoke($module, 'block', 'view', $delta); + } + } + + // Theme result + $result = "

" . t('Or browse available categories') .'

'; + $result .= '

' . t('Pick a category to launch a search.') . '

'; + foreach ($blocks as $facet_field => $block) { + $result .= theme('block', $block); + } + $result .= '
'; + apachesolr_has_searched(FALSE); + + return $result; +} + +/** * Execute a search results based on keyword, filter, and sort strings. * * @throws Exception