develodesign / magento2-module-typesense

Magento 2 Typesense integration, requires Algolia module, includes Hyva Support
GNU General Public License v3.0
17 stars 1 forks source link

Indexing error #11

Open web4exposure-org opened 1 year ago

web4exposure-org commented 1 year ago

When reindexing the algolia search products index, I get the following error:

Algolia Search Products index process error during indexation process: implode(): Argument #2 ($array) must be of type ?array, string given

0 /vendor/develodesign/magento2-module-typesense/Adapter/Client.php(109): implode()

The input in the implode is string(16) "default_products"

The search categories index gives me another error: Algolia Search Categories index process error during indexation process: No such entity with id = 20844

brideo commented 1 year ago

Hello @web4exposure-org,

Thank you for the report. To better understand the issue, could you please provide:

  1. The version of Magento you're using.
  2. Your Typesense configuration details (please omit any sensitive information).
  3. If available, any additional stack trace details. You might find these in var/logs.
  4. Also, does this error appear when you execute bin/magento index:reindex?

Thanks in advance!

web4exposure-org commented 1 year ago

Hi,

The version of Magento you're using.

Magento 2.4.6-p1

Your Typesense configuration details (please omit any sensitive information).

Enabled: Enable Cloud ID: null Admin API Key: xyz Search Only Key: xyz Path: null Port: 8108 Protocol: http Index Method: Typesense Only

This is a local environment with typesense running within a docker, settings:

  • Typesense 0.24.1
  • Port: 8108
  • Command: '--data-dir /data --api-key=xyz --enable-cors'

If available, any additional stack trace details. You might find these in var/logs.

When reindexing I get the following output:

bin/magento index:reindex algolia_categories algolia_products
Algolia Search Products index process error during indexation process:
implode(): Argument #2 ($array) must be of type ?array, string given
Algolia Search Categories index process error during indexation process:
No such entity with id = 20844

The only output from the logs is this:


==> var/log/system.log <==
[2023-08-21T06:46:40.396406+00:00] main.CRITICAL: implode(): Argument #2 ($array) must be of type ?array, string given [] []

==> var/log/debug.log <== [2023-08-21T06:46:40.396406+00:00] main.CRITICAL: implode(): Argument #2 ($array) must be of type ?array, string given [] []

==> var/log/system.log <== [2023-08-21T06:46:55.768187+00:00] main.CRITICAL: No such entity with id = 20844 [] []

==> var/log/debug.log <== [2023-08-21T06:46:55.768187+00:00] main.CRITICAL: No such entity with id = 20844 [] []



Also, does this error appear when you execute bin/magento index:reindex?
> As stated in the previous answer, yes.
brideo commented 1 year ago

Hi @web4exposure-org,

I've been unable to replicate this. Can you please confirm you have nodes set to your Docker host?

 bin/magento config:set typesense_general/settings/nodes 127.0.0.1

It's important to note that you must save this either in the command line or the backend of Magento, IE not directly in the database, as the indexes get created on save.

web4exposure-org commented 1 year ago

Hi, Yes I set this via the backend of magento. I'll try to set it up again in another environment to check if I get the same issue.

The product indexing error is in file Adapter/Client.php:deleteData If I put a return in this function before actually doing something, the whole product indexing works (but category indexing still doesnt work)

brideo commented 1 year ago

Hi @web4exposure-org - did you find a resolution to this one?

web4exposure-org commented 1 year ago

Hi, no, I still have the same problem on our staging environment. Are there some settings in the Algolia module I need to set? Or in the Typesense module?

brideo commented 1 year ago

The Typesense module extends the Algolia functionality, it adds an adapter to direct the indexing and search to your Typesense host, so you will need to configure Algolia to how you would like the autocomplete and instant search to display.

For Algolia to be set, you will need credentials in the Algolia configuration too. If you set Typesense index method to "Typesense Only", then it won't add any data to Algolia so you can just use a free demo account.

web4exposure-org commented 1 year ago

For Algolia to be set, you will need credentials in the Algolia configuration too.

Pretty important step which I didn't know!

Right now I have some updates after investigating the issues. The following issue: No such entity with id = 20844 was caused by a missing parent category. (some categories had 20844 as a parent ID, but this ID did not exist. I fixed it by inserting a new category into the database with ID 20844 and this fixed this issue)

However, the issue with implode(): Argument #2 ($array) must be of type ?array, string given is still occurring. I "fixed" this by adding a return; at line 105 in Client.php.

And a quick question; what's the difference between the Admin API key and Search only key, and how do I make sure this is set properly and securely? Right now I'm using the Typesense API key from my docker setup for both of these.

brideo commented 1 year ago

Hi @web4exposure-org - The admin api key will have write access where as the search only should only have read access.

I am not very familiar with the docker setup, I recommend running cloud https://cloud.typesense.org/

web4exposure-org commented 12 months ago

Hi, I want to come back at the following issue:

the issue with implode(): Argument #2 ($array) must be of type ?array, string given is still occurring. I "fixed" this by adding a return; at line 105 in Client.php.

The function deleteData() is getting an array with the following data as $indexName array(1) { [4499]=> string(4) "4499" }

The $data variable has the following value: testdefault_products.

Because of this data, I guessed these variables should be switched. If I switch these variables, I get the following error: Parameter filter_by must be provided.

If I put the filter_by key to the searchParameters, indexing works as expected, although I do not know for sure if this is the right solution.

public function deleteData($indexName, $data)
{
    $searchParameters = [
        'q' => implode(",", $indexName),
        'query_by' => 'objectID',
        'filter_by' => ''
    ];

    return $this->getTypesenseClient()->collections[$data]->documents->delete($searchParameters);
}