When searching nodes, I noticed that the score was null for every item in the results when some weight was given to the "Recently posted" factor.
Here is a sample query:
CREATE TEMPORARY TABLE temp_search_results SELECT i.type, i.sid, 5 * (6.98761587952 * i.relevance) + 2 * POW(2, (GREATEST(n.created, n.changed, c.last_comment_timestamp) - 1167851088) * 6.43e-8) AS score FROM temp_search_sids i INNER JOIN search_dataset d ON i.sid = d.sid AND i.type = d.type INNER JOIN node n ON n.nid = i.sid LEFT JOIN node_comment_statistics c ON c.nid = i.sid WHERE (d.data LIKE '% montreal %') ORDER BY score DESC
The score part of that query is built by node_search().
The problem lies with the above use of GREATEST(), but it is a problem only for MySQL 5.0.13+ (as found here):
Incompatible change: Before MySQL 5.0.13, GREATEST(x,NULL) and LEAST(x,NULL) return x when x is a non-NULL value. As of 5.0.3, both functions return NULL if any argument is NULL, the same as Oracle. This change can cause problems for applications that rely on the old behavior.
In my tests, comments were disabled so c.last_comment_timestamp was always NULL, causing the whole score to become NULL. Removing c.last_comment_timestamp from the arguments to GREATEST() fixes the problem, but this is probably not the best solution. ;-)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | node_search_2.patch | 4.42 KB | David Lesieur |
| #1 | node_search_1.patch | 971 bytes | David Lesieur |
Comments
Comment #1
David Lesieur commentedI needed a break. Here's a patch! ;-)
Comment #2
David Lesieur commentedBTW, this bug causes search results to appear in random order.
Comment #3
David Lesieur commentedHmm, there seem to be a larger issue with all those LEFT JOINs. If a NULL is involved in a comparison or arithmetical operation, the result will be NULL.
Comment #4
David Lesieur commentedComment #5
David Lesieur commentedPatch still applies. Might solve this issue too.
Comment #6
catchNo longer applies.
Comment #7
David Lesieur commentedMarking as duplicate since http://drupal.org/node/139537 and its related issues will eventually solve the problem.