When I index the new content of my site I found in the logs the following error:
"SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x98\xB3\xF0\x9F...' for column 'word' at row 7"
The reason is that in one my fields there is a text with emojis (emoticons) and the tables of the index have the collation "uf8_general_ci" and "utf8_bin".
I can save the text in Drupal without problems and it displays right, but when I try to re-index the content the error comes again and the process stops.
Would it be possible to change the collation of this tables to utf8mb4 so that they can support this kind of content. I changed it manually and it worked as expected.
Advice:
The problem is solved by enabling "transliteration" to the processor but I need to be able to find words with characters like äüßö
IS
Scenario 2:
1.- You have "search_api" and have a defined a index with fulltext fields into.
2.- You edit a node and insert some unicode (emojis) and text with characters like äüößáé.
3.- You DISABLE (or don't enable) "Transliteration" for the defined index processor.
4.- You try to re-index your content and it produces the error commented at the start of this text.
SHOULD
Scenario 2:
1.- You have "serach_api" and have a defined index with fulltext fields into.
2.- You edit a node and insert some unicode (emojis) and text with characters like äüößáé.
3.- You DISABLE "Transliteration" for the defined index processor.
4.- You try to re-index your content and it works right.
I hope I have described correctly the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2902907-3--4_byte_words.patch | 3.59 KB | drunken monkey |
| #3 | 2902907-3--4_byte_words--tests_only.patch | 2.51 KB | drunken monkey |
Comments
Comment #2
juagarc4 commentedComment #3
drunken monkeyThanks a lot for reporting this problem, and writing such a great issue summary!
The problem is easy enough to understand and I fear we've caused this ourselves: While Drupal itself defaults to using
utf8mb4, we actually have code in\Drupal\search_api_db\DatabaseCompatibility\MySql::alterNewTable()to change this to the other types. As explained in the comment:However, I guess this actually doesn't even apply to fulltext fields, since their field length is only 50 characters. So, while I'm not 100% sure, it seems like we can easily fix this. Patch attached, please test whether this resolves the problem for you! (You'll need to disable and re-enable the index to make it work, though.)
Also, you can probably just manually change the collation of your index's text table (
search_api_db_INDEX_text).Comment #4
borisson_Is the test-only patch supposed to pass?
Comment #5
juagarc4 commentedHi,
First of all, thank you for your quick response.
I've tested the patch "2902907-3--4_byte_words.patch" and it worked fine in my last tests.
I've recreated the site from scratch using config manager and some own build scripts.
The tables are now created using the new collation "utf8_general_ci" and "utf8mb4_bin" and the indexing works as expected.
Thank you very much!!
Comment #6
drunken monkeyHm, damn, no. Can't find any way to write that test so it passes with the patch but fails without it. I tried:
Can anyone think of another option? Otherwise, I guess we just have to go with that test (or just have no test at all, instead of one that's not correctly testing the regression).
@ juagarc4: Thanks a lot for reporting back! Good to hear it works as intended. (Even though the tests disagree …)
Comment #7
juagarc4 commentedHI @drunken monkey
I tried it too and I couldn't find any way to write that test so it passes with the patch but fails without it.
Could it be marked as incomplete?.
At least we have a message to consider when the test is executed.
For example:
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'Test incomplete because there is no way to do that it passes with the patch but fails without it.'
);
Thank you
Comment #9
drunken monkeyHm, OK. Still, thanks for trying!
Then I guess let's just commit it without a test.
Thanks again, everyone!
Comment #11
driskell commentedJust wanted to raise this change made queries that join the _text table to the other table unable to use the item_id PRIMARY key index, because one is utf8mb4 and the other is utf8. Thus when you have 10s of thousands of entries in the tables it is extremely slow and taxing on the database.
Raised it here - would be great to hear what the solution might be: https://www.drupal.org/project/search_api/issues/3227268