Hi,

I get this error on the a 404 page:

Notice: Trying to get property of non-object in search404_page() (line 216 of /sites/all/modules/search404/search404.module). Apache solr search still displays search results fine. It shows up for anonymous users as well. Any idea how to fix it? Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

somatics’s picture

I have this same problem, every time; so my dblogs are quite full of this error.

zyxware’s picture

@cmejo / @somatics - Thanks for reporting this error. I will need a bit of debugging help to solve this problem.

To solve the symptom you can replace the following line (line 416)

      $form['#action'] = '/' . $form['#search_page']->search_path . $form['#action'];

with the following.

      if (isset($form['#search_page']) && is_object($form['#search_page']) && isset($form['#search_page']->search_path)) {
        $form['#action'] = '/' . $form['#search_page']->search_path . $form['#action'];
      }

This should take care of the notices. Now we will need to figure out what causes this problem. Can you please try dpm($form) above the if condition and see what where is the search page set in the $form array. Are you using the latest version of the apache_solr module?

zyxware’s picture

Edit: Removing duplicate post.

cmejo’s picture

@xyzware Thanks for getting back to me. I don't have a line 416 in search404.module... I have it listed here:

    // Construct the search form.
    if ($type_search == 'apachesolr_search') {
      // Get Apachesolr search form
      module_load_include('inc', 'apachesolr_search', 'apachesolr_search.pages');
      $search_page = apachesolr_search_page_load('core_search');
      $form = drupal_get_form('apachesolr_search_custom_page_search_form', $search_page, $keys);
      // Set the action to point to the search page, otherwise form will submit to current 404 page
      $form['#action'] = '/' . $form['#search_page']->search_path . $form['#action'];
    }

Is it okay to replace that line there? Were you using the dev version to get it at line 416? Thanks!

somatics’s picture

I'm not in a position just now to manually patch the file, unfortunately. I don't understand the other thing you're asking me to do to troubleshoot. Can you please clarify what you want me to do?

zyxware’s picture

@cmejo - You can replace that last line starting with $form['#action'] = and replace it with the code I gave earlier. The code only adds an if condition to test the existence of the variables being used in the line to prevent the notice you are getting.

dpm($form); will print out the full form array that is returned from the drupal_get_form function call. You have to add it just after the line starting with $form = drupal_get_form('apachesolr_search_.... The problem apparently is that solr is returning something and the code is expecting something else. Do note that dpm will require the devel module to be enabled. You will probably want to do it on the dev environment of your site.

@somatics - The code I gave above should help prevent the notice messages flooding your dblog. Please see above for dpm.

Also can you also please let me know of the versions of solr and search404 modules used.

somatics’s picture

We're on Drupal 7.15 and using…

  • Apache Solr 7.x-1.0-rc3
  • Search 404 7.x-1.2
zyxware’s picture

@somatics - It looks like you are using the latest versions. I will need to see the dpm output before I can debug this further.

cmejo’s picture

@zyxware

Thanks! The code worked. I have devel installed and put dpm($form) on line 215 and got quite a bit of info. Is there something specific you are looking for?

Array 25 elements

#id (String, 11 characters ) search-form
#attributes (Array, 1 element)
#search_page (Array, 10 elements)
basic (Array, 17 elements)
#form_id (String, 41 characters ) apachesolr_search_custom_page_search_form | (Callback) apachesolr_search_custom_page_search_form();
#type (String, 4 characters ) form
#build_id (String, 48 characters ) form-eTITT1d4LQ3fLIhQPFwTsahGhIWIrMw8NGSo_Ik8DJM
form_build_id (Array, 18 elements)
#token (String, 41 characters ) apachesolr_search_custom_page_search_form | (Callback) apachesolr_search_custom_page_search_form();
form_token (Array, 17 elements)
form_id (Array, 18 elements)
#method (String, 4 characters ) post
#action (String, 7 characters ) /xmtext
#theme_wrappers (Array, 1 element)
#tree (Boolean) FALSE
#parents (Array, 0 elements)
#validate (Array, 0 elements)
#submit (Array, 1 element)
#theme (Array, 1 element)
#processed (Boolean) FALSE
#defaults_loaded (Boolean) TRUE
#required (Boolean) FALSE
#title_display (String, 6 characters ) before
#array_parents (Array, 0 elements)
#sorted (Boolean) TRUE

Let me know as I'm glad to help you with this issue!

zyxware’s picture

@cmejo - Thanks for the debug information.Can you please confirm that there is a string inside the $form['#search_page'] with key 'search_path' and that this is the solr search page path on your site. dpm($form['#search_page']['search_path']) should tell you this.

cmejo’s picture

I added the above code with a semicolon and saw a green box that says "search/site" and the regular this page doesn't exist, here is a search red box. Nothing relating to devel appears. I can confirm that it is the solr search page as it allows for filtering (faceted search). Thanks!

ecarty’s picture

I am seeing this Notice also, however, if I change line 216 of search404.module from:
$form['#action'] = '/' . $form['#search_page']->search_path . $form['#action'];
to
$form['#action'] = '/' . $form['#search_page']['search_path'] . $form['#action'];
I don't get the notice message.

My understanding is that $form['#search_page'] is an array, but the '$form['#search_page']->' syntax is addressing it as an object - is this right?

cbrody’s picture

I can confirm that the change at #12 fixes a problem where the search form destination was being set to @keys with no preceding URL.

JordanMagnuson’s picture

#12 fixed this for me as well.

Also using 7.x with latest apachesolr.

heddn’s picture

heddn’s picture

Status: Active » Needs review
JordanMagnuson’s picture

Status: Needs review » Reviewed & tested by the community

4 confirmed working (if counting #12 and #15). Setting to RTBC.

zyxware’s picture

Assigned: Unassigned » zyxware
Status: Reviewed & tested by the community » Fixed

This has been committed to the 7.x-1.x branch

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.