--- apachesolr.module 2008-04-20 10:14:45.000000000 -0400 +++ apachesolr_new.module 2008-05-30 14:14:32.000000000 -0400 @@ -42,6 +42,12 @@ function apachesolr_settings() { '#default_value' => variable_get('apachesolr_path', '/solr'), '#description' => t('Path that identifies the Solr request handler to be used. Leave this as /solr for now.'), ); + $form['apachesolr_i18n'] = array( + '#type' => 'checkbox', + '#title' => t('Index language'), + '#default_value' => variable_get('apachesolr_i18n', ''), + '#description' => t('Index node language (only effective if i18n is installed.'), + ); return system_settings_form($form); } @@ -199,6 +205,9 @@ class ApacheSolrUpdate { module_invoke_all('apachesolr_update_index', &$document, $node); $fields = array('title', 'body', 'type', 'uid', 'changed', 'nid', 'comment_count', 'name'); + if(variable_get('apachesolr_i18n', '')) { + $fields[] = 'language'; + } foreach ((array)$node as $key => $value) { if (in_array($key, $fields)) { $document->$key = $value; @@ -315,10 +324,15 @@ function apachesolr_block($op = 'list', } } + // Languages block + if(variable_get('apachesolr_i18n', '')) { + $blocks['language'] = array('info' => t('ApacheSolr: Languages')); + } + //i18n_supported_languages() + // Sorting block $blocks['sort'] = array('info' => t('ApacheSolr: Sorting')); return $blocks; - case 'view': if (apachesolr_has_searched()) { // Get the query and response. Without these no blocks make sense. @@ -401,8 +415,38 @@ function apachesolr_block($op = 'list', return; } } - switch ($delta) { + case 'language': + $languages = i18n_supported_languages(); + if (is_array($response->facets->language)) { + $contains_active = FALSE; + foreach ($response->facets->language as $t => $count) { + unset($unclick_link); + unset($active); + $new_query = clone $query; + if ($active = $query->has_field('language', $t)) { + $contains_active = TRUE; + $new_query->remove_field('language', $t); + $path = 'search/'. arg(1). '/'. $new_query->get_query(); + $unclick_link = theme('apachesolr_unclick_link', $path); + } + else { + $new_query->add_field('language', $t); + $path = 'search/'. arg(1). '/'. $new_query->get_query(); + } + $countsort = $count == 0 ? '' : 1 / $count; + // if numdocs == 1 and !active, don't add. + if ($response->numFound == 1 && !$active) { + // skip + } + else { + $types[] = theme('apachesolr_facet_item', $languages[$t], $count, $path, $active, $unclick_link); + } + } + $output = theme('apachesolr_facet_list', $types); + return array('subject' => t('Language'), 'content' => $output); + } + break; case 'type': if (is_array($response->facets->type)) { $contains_active = FALSE;