Hi
We're using

Search API Autocomplete https://drupal.org/project/issues/search_api_autocomplete

with Search API 7.x-1.9 https://drupal.org/project/search_api

on a site set up with Solr (Websolr) serving nodes in both English and German.

I'm looking to be able to filter the results by ss_search_api_language field which is presently not happening and as such i get autocomplete results for all both languages.

What would be the correct approach to deal with this?

Thanks

Comments

f0ns’s picture

Also looking for a solution to make sure only suggestions of the current active language global $language->language; are shown.

f0ns’s picture

Fixed this issue, made a custom module with this hook:

function filter_by_language_search_api_query_alter(SearchApiQueryInterface $query) {

  //if query is of type search_api_autocomplete we will add our extra language filter
  if (strpos($query->getOption('search id'), 'search_api_autocomplete:') !== false) {
      dsm($query->getOption('search id'));

      global $language;

      $filter = $query->createFilter('AND');
      $filter->condition('language', $language->language, '==');
      $query->filter($filter);

  }
}

Make sure the language of your nodes are in the index.

drunken monkey’s picture

Priority: Major » Normal
Status: Active » Fixed

Glad that you could solve this yourself, and thanks a lot for posting your solution!
However, the last three lines could actually be written as one:

$query->condition('language', $language->language, '==');

Creating a new filter for a single condition (or, "AND" conditions in general) isn't necessary.

drunken monkey’s picture

Oh, and the operator should be =, not ==! If the latter works it's only due to a glitch in whatever backend you are using and not something you should rely on.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

pinueve’s picture

Hi drunken monkey
I need some help, I manage to setup in Acquia cloud a multilingual site (with lingotek D7 module) having Aquia search (solr), search api and search api autocomplete, I tried above code with no luck, site is English based and just (for start) I added spanish, autocomplete only works in English, viewing site in spanish, query runs in english object, could you please point me where I can alter query so search is done over translated text?