I have a use case where I have taxonomy terms in the search result next to nodes. This results in the following warning:

Warning: Creating default object from empty value in ds_search_search_page() (line 343 of ds_search.module).

The warning is due to the use of the key '#node' on line 343:

$build['search_results'][$id]['#node']->ds_search_zebra = $parity;

Entity types other than node will not have this array key, but a key that corresponds with their type. For taxonomy terms, the key is '#term'.

I changed the code into the following to get rid of the warning:

      switch ($build['search_results'][$id]['#entity_type']) {
        case 'node':
          $key = '#node';
          break;

        case 'taxonomy_term':
          $key = '#term';
          break;

      }
      $build['search_results'][$id][$key]->ds_search_zebra = $parity;

This fixes my issue, but there might be a nicer way to determine the right key for an entity type so that it can be solved in a more generic way?

Comments

marty2081’s picture

This might be cleaner already so that when the key is simply the entity_type the module will work by default and you only have to add the exceptions:

  switch ($build['search_results'][$id]['#entity_type']) {
     case 'taxonomy_term':
       $key = '#term';
       break;

      default:
       $key = '#' . $build['search_results'][$id]['#entity_type'];
       break;

   }
   $build['search_results'][$id][$key]->ds_search_zebra = $parity;
JRZ-2’s picture

Hello,

I have a similar issue getting the following message :
Undefined index: location_taxonomize dans ds_search_search_page() (ligne 264 dans ----/modules/ds/modules/ds_search/ds_search.module).

I'm using apache solr, Facet api, location taxonomize and display suite search.

On the result page, taxonomy terms are not displayed at all under the "other" group, though the facet indicates that they are found.

Thanks for your insights

swentel’s picture

Status: Active » Closed (fixed)

Committed based on #2 which should work fine in most cases now indeed.

Note that the group by only works for nodes, so that can't be fixed at all.

swentel’s picture

Issue summary: View changes

Anonymized the warning line (removed the site URL and filepath) and translated Dutch words to English for the non-Dutch audience ;)