Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Found by Robert
Comment | File | Size | Author |
---|---|---|---|
#9 | default_search_factor-D5.patch | 2.01 KB | floretan |
#5 | default_search_factor.patch | 1.95 KB | floretan |
#1 | default_search_factor.patch | 1.94 KB | floretan |
Comments
Comment #1
floretan CreditAttribution: floretan commentedTo reproduce:
0. Enable the search module.
1. Set all search factor weights to 0 (this disables all of them).
2. Create a page node with the keyword "drupal".
3. Run cron.
4. Search for the keyword "drupal". Division by zero error in node.module (in the implementation of hook_search).
The node search code already defaults to using keyword relevance as the default search factor when none are specified:
But
count($ranking)
is only zero when all search factors have a zero weight, meaning that their total weight is zero, which leads to the division by zero a little further in the code.This patch doesn't change the algorithm, it just changes the code to use a proper if-statement. When using the default search factor, the total weight can safely be set to 1 (for those who are into mathematics and set theory, we can do this because 1 is the identity element of real numbers under multiplication, but that's beyond the scope of this patch).
Comment #2
Senpai CreditAttribution: Senpai commentedTested and Working As Intended. I followed these steps:
1. Enabled the search module.
2. Set all search factor weights to 0.
3. Created a page node with the word "drupal" as the body text.
4. Created an article node with the word "drupal" as the body text.
5. Ran cron using devel.mod.
6. Searched for the keyword "drupal".
7. Received both pieces of content in the resulting list, with no divide-by-zero errors present in drupal_set_message().
Comment #3
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
The patch did not apply against DRUPAL-6 so it will need a reroll.
Comment #4
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
The patch did not apply against DRUPAL-6 so it will need a reroll.
Comment #5
floretan CreditAttribution: floretan commentedRe-rolled for drupal 6. The only change was the spacing around the concatenation operator.
Comment #6
Gábor HojtsyThanks, committed to Drupal 6!
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8
catchStill a valid bug in D5.
Comment #9
floretan CreditAttribution: floretan commentedPatch still applied with some offset. Re-rolling without changes.
Comment #10
drummCommitted to 5.x.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.