Problem/Motivation

Multilingual websites are throwing the below error when they are not configured to support multilingual Algolia indexes.

The website encountered an unexpected error. Please try again later.AlgoliaSearch\AlgoliaException: Index {MY_INDEX}_en does not exist in AlgoliaSearch\Client->doRequest() (line 1371 of /private/var/www/sites/mskcc_build/vendor/algolia/algoliasearch-client-php/src/AlgoliaSearch/Client.php).

AlgoliaSearch\Client->request(Object, 'POST', '/1/indexes/{MY_INDEX}__en/query', Array, Array, Array, 1, 5, Array) (Line: 619)
AlgoliaSearch\Index->search('*', Array) (Line: 466)
Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend->search(Object) (Line: 468)
Drupal\search_api\Entity\Server->search(Object) (Line: 535)
Drupal\search_api\Query\Query->execute() (Line: 308)
search_api_preprocess_search_api_index(Array, 'search_api_index', Array) (Line: 287)

Proposed resolution

Make multilingual Algolia index support a configuration setting and prevent fatal errors when a multilingual Algolia index is missing.

Remaining tasks

TDB

User interface changes

New configuration settings

API changes

TDB

Data model changes

N/A

Release notes snippet

TDB

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jrockowitz created an issue. See original summary.

nikunjkotecha’s picture

Status: Active » Needs review
StatusFileSize
new10.08 KB

Initial patch with approach to make suffix optional

@Jacob: Please review updated INSTALL.md and help confirm if this looks OK.

Note: I renamed txt to md to ensure they are better readable.

jrockowitz’s picture

@nikunjkotecha Thank you for responding so quickly. I will review the patch as soon as I have time available.

ben.hamelin’s picture

Just applied this patch and so far it's working to solve the main indexing issue.

One thing I ran into was when clearing the indexes - was hitting an error because not all the indexes were setup but the loop was trying to clear all of them.

Under the content configuration for the index, we have the language options. I feel like those settings should be respected during the delete items loop. So replacing the getLanguages() output with the configured languages from the content datasource.

benjy’s picture

Status: Needs review » Needs work

Setting back to NW for the last comment, sounds like we haven't handled all places where the language suffix should be taken into account.

nikunjkotecha’s picture

Status: Needs work » Needs review
StatusFileSize
new14.62 KB

I've added some of the code formatting fixes and bugs too

nikunjkotecha’s picture

Status: Needs review » Needs work
nikunjkotecha’s picture

> So replacing the getLanguages() output with the configured languages from the content datasource.

Need to check this.

nikunjkotecha’s picture

Status: Needs work » Needs review
StatusFileSize
new3.3 KB
new15.93 KB

Use languages from datasource configuration now.

Status: Needs review » Needs work

The last submitted patch, 9: 3106901-9.patch, failed testing. View results

nikunjkotecha’s picture

Status: Needs work » Needs review

Build was successful and couldn't find any errors too on the console https://dispatcher.drupalci.org/job/drupal8_contrib_patches/35263/console

jlongbottom’s picture

StatusFileSize
new15.9 KB

Patch works great, however it did not apply cleanly using composer due to differences in the .info file due to extra information added by Drupal.org packaging script.

Here is my patch, which basically just accounts for the extra white space added to the info file.

nikunjkotecha’s picture

Thanks @Justin

Apart from that do you think this can be moved to RTBC?

jlongbottom’s picture

I was a bit confused why search_api_autocomplete is now a required dependency after applying the patch. Seems like something that could be configured. Other than that, it seems to work as intended.

nikunjkotecha’s picture

Support for autocomplete is added in the module and its classes are used, if it won't be there it might break. When checking with drupal-check for code analysis and deprecations I found out it was throwing error for missing classes. This can still stay disabled though but we just need the code to be there so it doesn't break.

kknoer’s picture

I am still having issues running the latest 2.0.0-alpha1 version of the module.

If I create an index on a multilingual site, one language Spanish, I am unable to open any index in the admin configuration page and I receive the same mentioned error:

The website encountered an unexpected error. Please try again later.

AlgoliaSearch\AlgoliaException: Index {index_name_here}_en does not exist in AlgoliaSearch\Client->doRequest()

I installed the module via: composer require "drupal/search_api_algolia:^2.0". I have no pending updates and I have cleared all caches.

I am trying to get this module upgraded in preparing to upgrade to Drupal 9.

Any ideas?

nikunjkotecha’s picture

@Keith are you using the patch from this ticket? Without that you will need indexes with language suffix

mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/search_api_algolia.info.yml
    @@ -6,4 +6,5 @@ core_version_requirement: ^8 || ^9
    + - search_api_autocomplete:search_api_autocomplete
    
    +++ b/src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
    @@ -725,11 +701,17 @@ class SearchApiAlgoliaBackend extends BackendPluginBase implements PluginFormInt
    +    // This function will be used only is search_api_autocomplete is enabled
    +    // and used. We have it here to add the support but it might never be used
    +    // in normal cases.
    

    This part contradicts with a required dependency to search_api_autocomplete. Shall we make it optional as the comments suggests?

  2. +++ b/src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
    @@ -29,14 +31,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
    -class SearchApiAlgoliaBackend extends BackendPluginBase implements PluginFormInterface {
    +final class SearchApiAlgoliaBackend extends BackendPluginBase implements PluginFormInterface {
    

    Is this really needed?

    This prevents any inheritance in case there is a need for custom implementation.

    I would advise against this change, especially it being done in #3106901: Make language suffix a configuration issue.

mbovan’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

Updated the affected version.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new15.82 KB
new3.21 KB

Updates:

  • Rerolled the patch for 2.0.x
  • Addresssed points in #18
marijan gudelj’s picture

StatusFileSize
new14.56 KB

Here is a patch with this fix and also updated the Algolia version to 2.0 found https://www.drupal.org/project/search_api_algolia/issues/3091525.

Without this patch you cannot install new version and apply this fix.

Status: Needs review » Needs work

The last submitted patch, 21: 3106901-21.patch, failed testing. View results

Heisen-blue’s picture

I've just tested the patch submitted on #20, it works great.

  • nikunjkotecha committed 70f3afd on 3.0.x
    Issue #3106901 by nikunjkotecha, mbovan, jlongbottom, Marijan Gudelj,...
nikunjkotecha’s picture

Version: 2.0.x-dev » 3.0.x-dev
nikunjkotecha’s picture

Status: Needs work » Fixed

Merged in https://git.drupalcode.org/project/search_api_algolia/-/merge_requests/4 after fixing few issues and also updated readme.

Credits given to all involved in this ticket and https://www.drupal.org/project/search_api_algolia/issues/3091525

Status: Fixed » Closed (fixed)

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