0

We have a view that works with Search API and Solr search. The multiple search terms work with single quotes and with no quotes. I want to make the search terms work with double quotes as well. The issue is also listed here without a fix:

https://www.drupal.org/project/search_api/issues/2141575

I found that I can change the parse mode in the View > Query > Settings to direct method and the term with double quotes work just fine. I want to make this change using hooks. I have tried hook_search_api_views_query_alter and it does not work. Does anyone know how to change the parse mode in the query settings using hooks?

1

On Drupal 7, I've achieved this by using hook_views_pre_build() since this hook is executed before hook_views_pre_execute() and hook_search_api_views_query_alter(). Using code similar to the following will do the job.

$options = $view->display_handler->get_option('query');
$options['options']['parse_mode'] = 'TYPE_OF_PARSE_MODE';
$view->display_handler->set_option('query', $options);

Note that TYPE_OF_PARSE_MODE can be:

  • Direct query - direct
  • Single term - single
  • Multiple terms - terms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.