I am using a Drupal installation with PostgreSQL 8.4.4. After setting up the search box (with the Acquia Prosper theme 6.x-1.0-beta4), re-indexing my site, and attempting to search, I get the following error ...
* warning: pg_query(): Query failed: ERROR: operator does not exist: integer || integer LINE 1: ...d), MAX(n.changed), MAX(c.last_comment_timestamp) || 1) - 12... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. in /var/www/foo/includes/database.pgsql.inc on line 139.
* user warning: query: SELECT COUNT(*) FROM (SELECT i.type, i.sid, 5 * (4.1443562157055 * SUM(i.score * t.count)) + 5 * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp) || 1) - 1282555024) * 6.43e-8) + 5 * (2.0 - 2.0 / (1.0 + MAX(c.comment_count) * 1)) AS score FROM search_index i INNER JOIN search_total t ON i.word = t.word INNER JOIN node n ON n.nid = i.sid LEFT JOIN node_comment_statistics c ON c.nid = i.sid WHERE n.status = 1 AND (i.word = 'love') AND i.type = 'node' GROUP BY i.type, i.sid HAVING COUNT(*) >= 1) n1 in /var/www/foo/modules/search/search.module on line 958.
* warning: pg_query(): Query failed: ERROR: operator does not exist: integer || integer LINE 1: ...d), MAX(n.changed), MAX(c.last_comment_timestamp) || 1) - 12... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. in /var/www/foo/includes/database.pgsql.inc on line 139.
* user warning: query: SELECT i.type, i.sid, 5 * (4.1443562157055 * SUM(i.score * t.count)) + 5 * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp) || 1) - 1282555024) * 6.43e-8) + 5 * (2.0 - 2.0 / (1.0 + MAX(c.comment_count) * 1)) AS score FROM search_index i INNER JOIN search_total t ON i.word = t.word INNER JOIN node n ON n.nid = i.sid LEFT JOIN node_comment_statistics c ON c.nid = i.sid WHERE n.status = 1 AND (i.word = 'love') AND i.type = 'node' GROUP BY i.type, i.sid HAVING COUNT(*) >= 1 ORDER BY score DESC LIMIT 10 OFFSET 0 in /var/www/foo/modules/search/search.module on line 958.
I **think** the problem is that PostgreSQL does not support the operator "||" as a logical operator. Changing it to an "OR" will not work because both sides of the expression need to be a boolean type. A possible solution is to use COALESCE. So changing line 1238 of node.module from ...
$ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp) || 1) - %d) * 6.43e-8)';
... to ...
$ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), COALESCE(MAX(c.last_comment_timestamp),1)) - %d) * 6.43e-8)';
**should** work for both PostgreSQL and MySQL.
Comments
Comment #1
asena commentedActually I am not sure what you want when "MAX(c.last_comment_timestamp)" is 0 . I don't know if this case is possible because I am a new to all of this but I thought I would add that using COALESCE as I have suggested will result in a value of 0 in this case but "MAX(c.last_comment_timestamp) || 1" will result in a value of 1 (I think based on what little I know of MySQL).
Comment #2
lsparreb commentedThe problem is the difference in the meaning of the "||" operator.
(and Oracle) Example : 'ABC' || 'DEF' results in 'ABCDEF'.
See also : http://www.postgresql.org/docs/8.4/static/functions-binarystring.html
Example : "select 1 || 0" results in "1". This is because of one of the integers has a value greater or equal 1.
See : http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_or
So, the change should be in the "
(GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp) || 1)" part.To avoid the problem mentioned by asena on august 24, 2010 - 09:07, the following code is working and may be functional correct:
$ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp), 1) - %d) * 6.43e-8)';I requested a priority-change to major. Search functionality is broken on a Drupal + PostGreSQL implementation.
Comment #3
lsparreb commentedComment #4
damien tournoud commented*sigh*
This is a duplicate of #488166: Search relevance calculation fails if last_comment_timestamp is NULL.