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);

CommentFileSizeAuthor
#2 3361041-2--fix_negative_scores.patch814 bytesdrunken monkey
Database.php_.patch562 bytesAnonymous (not verified)

Comments

Anonymous’s picture

BigDave91 created an issue. See original summary.

drunken monkey’s picture

Component: General code » Database backend
Status: Active » Needs review
StatusFileSize
new814 bytes

Thanks a lot for reporting this problem!
You’re right, seems for extremely high scores, casting the float score 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.)

drunken monkey’s picture

Assigned: » Unassigned
Anonymous’s picture

Thank you very much @drunken monkey. I just tested the patch and the problem was resolved.

  • drunken monkey committed 855a5ee2 on 8.x-1.x
    Issue #3361041 by BigDave91, drunken monkey: Fixed integer overflow...
drunken monkey’s picture

Status: Needs review » Fixed

Good to hear, thanks a lot for testing!
Merged. Thanks again!

Status: Fixed » Closed (fixed)

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