2

I have just discovered that the Drupal 7 search on my website is giving 'website encountered an unexpected error. Please try again later.' to users who are not logged in. (it's fine for logged in users.)

Checking the logs, I can see that when a non-logged in user runs a search it causes a mySQL error, which looked like there was a problem because I'd excluded content type admin_only_help from public search.

OK, I'll include that content type in search. Nope, still the same error. OK, re-index the search: nope, won't re-index the search, stalls at 0%.

I tried:

  • setting content type admin_only_help to be indexed.

  • unpublishing all nodes of content type admin_only_help

  • re-indexing the search from the admin panel (it stalls)

  • running drush search-index from the command line (it stalls)

  • turning off the Custom Search module

  • clearing cache (after all of the above).

I'd be very grateful for any further suggestions.

The exact error from my logs is:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have 
an error in your SQL syntax; check the manual that corresponds to your MySQL 
server version for the right syntax to use near 'WHERE (c.nid = '873') AND 
(c.status = '1') AND (n.type <> 'admin_only_help')' at line 2: SELECT COUNT(*) 
AS expression FROM {comment} c INNER JOIN {node} n ON n.nid = .nid WHERE 
(c.nid = :db_condition_placeholder_0) AND (c.status = 
:db_condition_placeholder_1) AND (n.type <> :db_condition_placeholder_2) ; 
Array ( [:db_condition_placeholder_0] => 873 [:db_condition_placeholder_1] => 
1 [:db_condition_placeholder_2] => admin_only_help ) in PagerDefault-
>execute() (line 74 of /home/mysite/public_html/includes/pager.inc).

Edit with update: I tried completely removing the problem content-type admin_only_help and completely removing the two nodes that belonged to that content type.

Now I have this error:

SQLSTATE[42000]: Syntax error or access violation: 1064 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 
'WHERE (c.nid = '421') AND (c.status = '1')' at line 2: SELECT COUNT(*) AS expression 
FROM {comment} c INNER JOIN {node} n ON n.nid = .nid WHERE (c.nid = :db_condition_placeholder_0) 
AND (c.status = :db_condition_placeholder_1) ; 
Array ( [:db_condition_placeholder_0] => 421 [:db_condition_placeholder_1] => 1 ) in PagerDefault->execute() 
(line 74 of /home/mysite/public_html/includes/pager.inc).

And I still can't re-index my database.

6
  • Can you post the error please?
    – Kevin
    Jan 27, 2017 at 17:28
  • Sure, I've updated the question.
    – Victoria
    Jan 27, 2017 at 17:51
  • The error states that it still tries to exclude the content type admin_only_help in this part: AND (n.type <> 'admin_only_help') and in this part: AND (n.type <> :db_condition_placeholder_2). If this error message is created after you tried to include the content type in the search again, it had no effect, the content type is still being excluded. Jan 29, 2017 at 12:33
  • Yes, I know - the problem is that I can't include it! I have changed the relevant search checkbox, but it's still triggering the error. I'm not sure where the database setting is, maybe that's the next thing to investigate.
    – Victoria
    Jan 30, 2017 at 10:55
  • There is an error when joining the node table: "n.nid = .nid". The error is the same in both queries you postet. So the admin help content does not seem to be the problem. There seems to be a problem creating the pager of your search results. Are you getting this error when only using the core search module? And another esit: Are you usi g the latest version of Drupal? It looks like there are changes between you version and the latest one in the file generating the pager.
    – schlicki
    Jan 30, 2017 at 19:37

1 Answer 1

0

I have traced this particular problem to the Node View Permissions Module. Disabling this module allowed my search to re-index and be seen by users who are not logged in.

There is a patch available here : https://www.drupal.org/node/2564273

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.