On a multilingual Drupal box I always get the following user warning whenever I click on the "Attachments" tab on the Drupal Search page:
user warning: Unknown column 'n.language' in 'where clause' query: SELECT SUM(i.score * t.count) AS score FROM search_index i INNER JOIN search_total t ON i.word = t.word INNER JOIN files f ON f.fid = i.sid WHERE f.status = 1 AND (n.language ='en' OR n.language ='' OR n.language IS NULL) AND (i.word = 'wagen') AND i.type = 'file' GROUP BY i.type, i.sid HAVING COUNT(*) >= 1 ORDER BY score DESC LIMIT 0, 1 in /var/www/html/modules/search/search.module on line 946.
This error message doesn't appear in other search tabs (Content, Users).
Best regards,
Olivier
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 548156.patch | 1019 bytes | benoitg |
Comments
Comment #1
ShutterFreak commentedI tested this bug on beta3. The result is still the same. But I found a fix.
I'm trying to understand which module inserts the "
AND (n.language ='en' OR n.language ='' OR n.language IS NULL)" fragment in the query. My best guess is that the default behavior of do_search is to look at nodes which are listed in thenodetable, often referenced asn, and which indeed contains alanguagecolumn.A first check I did in the code was the value for
i.typein the firstdo_search()query, which resulted from trying out the following SQL queries:Although there are two
do_search()queries insearch_files_attachments.modulethe first apparently does nothing since there's no 'file' type in my search index. Maybe this is from a previous version of this module? Or is it from another module?Rewriting the score as i.score * t.count and only looking at 'search_files_att' type, this query yields:
Time to revisit the 'n.language' error. To get to the language given a file, the only way I know is by going through the upload table using 'fid' as join key, and then to the node table via 'nid'. When I add the 2 missing
LEFT JOINstatements (to get rid of the missing 'n.language') I get the same query result as with the previous query:I now understand how both do_search queries work. The first one will look for language-tainted 'file' entries. That query bails out as soon as you configure your Drupal to serve content in more than one language, yielding the aforementioned error message. The fix is simple: add the missing links to get to the language. The second query is not hindered by a language check hence it runs smoothly.
I managed to get rid of the error reported in my bug report by editing the first
do_search()statement insearch_files_attachments.moduleby adding 2LEFT JOINstatements as follows:Unfortunately I have no cvs or svn installed on my machine hence I can't easily create a patch. The fix is really only one line of code.
Hope this helps!
Olivier
Comment #2
benoitg commentedYour solution works fine.
I created a patch against6.x-2.0-beta3 and attached it to this issue.
Comment #3
jrglasgow commentedthis patch has been committed
Comment #4
jrglasgow commentedComment #5
thl commentedThanks for the investigation, ShutterFreak. And the other fellows for creating and committing the patch. Just for the record, see
search_files_attachments.module revision 1.1.2.25
search_files_attachments.module revision 1.1.2.27
Fixed.