Problem/Motivation
As soon as i tried to index my search API i get the following error:
error: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'score' at row 8: INSERT INTO "search_api_db_social_all_text"
Steps to reproduce
I am not sure how to reproduce this in another project. The problem was based on the rule that "Taken from core search to reflect less importance of words later in the text." Because the item has a long title it gets a super low score (high integer) that ends up returning a negative value and there for cannot be inserted to the table. The score column is "Unsigned" and therefore can't be a negative value.
Proposed resolution
My propose solution is to add max() around the current min() function. This wil make sure that if the value of the min() function a negative value is. Then the end result wil be a score of 0.
The score would then be determined by => $score = max(min((int) $score, 4294967295), 0);
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3361041-2--fix_negative_scores.patch | 814 bytes | drunken monkey |
| Database.php_.patch | 562 bytes | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) commentedBigDave91 created an issue. See original summary.
Comment #2
drunken monkeyThanks a lot for reporting this problem!
You’re right, seems for extremely high scores, casting the
floatscore to an integer can actually result in a negative value. To be honest, I didn’t think this problem existed in a scripting language like PHP, the problem seems much too low-level for that. However, it clearly does, but the solution is fortunately very simple: just first determine the minimum and then cast to an integer. (Floats will never have this problem, as they have an explicit “infinity” value for when they exceed their maximum. (Which is, also, ridiculously high.))Patch attached, please test/review!
(Regarding your patch: Please use these instructions when creating patches so others can easily apply them.)
Comment #3
drunken monkeyComment #4
Anonymous (not verified) commentedThank you very much @drunken monkey. I just tested the patch and the problem was resolved.
Comment #6
drunken monkeyGood to hear, thanks a lot for testing!
Merged. Thanks again!