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.
If I set more than one weight to > 0 on the search configuration page, the node search fails and the dblog has an error message like:
PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT i.type AS type, i.sid AS sid, SUM(CAST(:multiply_0 AS DECIMAL) * COALESCE(( 2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * CAST(:scale AS DECIMAL))), 0) / CAST(:total_0 AS DECIMAL) + CAST(:multiply_1 AS DECIMAL) * COALESCE(( POW(2.0, (GREATEST(n.created, n.changed) - :node_cron_last) * 6.43e-8)), 0) / CAST(:total_1 AS DECIMAL)) AS calculated_score FROM {search_index} i INNER JOIN {node} n ON n.nid = i.sid INNER JOIN {search_total} t ON i.word = t.word LEFT JOIN {node_comment_statistics} node_comment_statistics ON node_comment_statistics.nid = i.sid INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type WHERE (n.status = :db_condition_placeholder_0) AND( (i.word = :db_condition_placeholder_1) )AND (i.type = :db_condition_placeholder_2) AND( (d.data LIKE :db_condition_placeholder_3 ESCAPE '\\') ) GROUP BY i.type, i.sid HAVING (COUNT(*) >= :matches) ORDER BY calculated_score DESC LIMIT 10 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => blog [:db_condition_placeholder_2] => node [:db_condition_placeholder_3] => % blog % [:matches] => 1 [:scale] => 0 [:multiply_0] => 4 [:node_cron_last] => 1271277590 [:multiply_1] => 6 [total_0] => 10 ) in PagerDefault->execute() (line 93 of /mnt/www/html/tangle001/docroot/includes/pager.inc).
Comment | File | Size | Author |
---|---|---|---|
#7 | 771596-test-and-fix.patch | 2.56 KB | jhodgdon |
#7 | 771596-failing-test.patch | 1.94 KB | jhodgdon |
#1 | Search-settings.png | 48.1 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commenteddoh, attached screenshot disappeared. Here it is:
Comment #2
jhodgdonThat doesn't look good! Good catch!
We should fix it and also make a test.
Since it's a crash situation (PDO exception arising from using the Drupal core UI in a reasonable way), I think status should be critical on this one.
Comment #3
jhodgdontagging
Comment #4
jhodgdonIt looks like the error in the query is that placeholder :total_0 in the query was given as just total_0 in the arg list.
Comment #5
jhodgdonOh, and :total_1 is also missing.
Comment #6
jhodgdonHah! I think I found the problem and have a fix. Writing tests... will report back shortly.
Comment #7
jhodgdonHere's a patch. If you apply just the search.test part of the patch, you get an exception much like the one reported above. If you also apply the search.extender.inc part of the patch, the test passes.
I'll attach this as two patches: the full patch (test + fix) and just the failing test (so we can verify that the test bot agrees that the added test is a good one for revealing this bug).
Comment #9
jhodgdonThere you go. The "test and fix" patch needs review. Obviously don't just add the "failing test" patch. :)
Comment #10
pwolanin CreditAttribution: pwolanin commentedAh yes -
$i++
would help.Change makes sense, and added testing is lovely.
Comment #11
jhodgdonNot only $i++ but also the : was missing.
Comment #12
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.