The suggestion feature and the spell checker are not present when i use this module to render the solr search. IS there an option to turn those on or are these features not present with views integration>?

CommentFileSizeAuthor
#2 spellchecker.patch975 bytesdomidc

Comments

domidc’s picture

Subscribing

domidc’s picture

StatusFileSize
new975 bytes

You could add suggestions to apache solr this way
In apache_solr_views_query.inc in the execute function above the $response = $this->_solr_service ...

      //add spellchecking on a field
      if (variable_get('apachesolr_search_spellcheck', TRUE)) {
      	$this->_params['spellcheck.q'] = $view->exposed_input['text'];
      	$this->_params['spellcheck'] = 'true';
      }
      
      $response = $this->_solr_service->search($this->_query, $offset, $view->pager['items_per_page'], $this->_params);

Then in a custom module you could get the suggestions like this and call them from a block or something. (the apache solr views module stores the result so we can get it)

function get_suggestions() {
  $apachesolr_has_searched = apachesolr_has_searched();
  $response = apachesolr_static_response_cache();
  
  if ($apachesolr_has_searched && $response && variable_get('apachesolr_search_spellcheck', TRUE)) {
    $suggestions = get_object_vars($response->spellcheck->suggestions);
    if ($suggestions) {
      foreach ($suggestions as $suggestion) {
        foreach ($suggestion->suggestion as $part) {
          $options['query']['text'] = $part;
          $list[] = l($part, 'solr', $options);
        }
      }
    }
  }
  return theme('item_list', $list);
}

Perhaps this could be included in the module?

Scott Reynolds’s picture

I think the right approach would be to attach the spellchecker suggestions to the exposed filter form. So in that form you would do something like

$form['suggestions'] = array(
'#type' => 'markup',
'#value' => theme('solr_views_suggestions', $response)

Then the default theme implementation for the suggestions could be an item list. And doing this allows some module to do a form_alter on the form and put '#access' => FALSE if they don't want suggestions.

Thats the approach I like.

scotjam’s picture

Edit!

By exposed filter form, you're referring to the views-exposed-form.tpl.php, right?

Can anyone help explain this in more simple steps please?

dirtysteak’s picture

Would love to see this functionality, right now the search field is a bit crippled on our site because of this....

Subscribing.

dries arnolds’s picture

I'm also anxiously waiting for this feature. Scott's approach seems fine.

LetUsBePrecise’s picture

We also need this feature on our site... subscribing.....

lucasvm’s picture

the path did not work for me, im also using exposed form to show the apache solr result and perform the search and i cant see the spellcheck and i really need it

kenorb’s picture

Issue summary: View changes
Status: Active » Needs review