We are getting a lot of notifications in the dblog due to the $fields array miss-matching with the $mlt['fields'] and creating issues when trying to access fields that didnt exist like the below for example.

Notice: Undefined index: field_sponsors in SearchApiSolrService->search() (line 876 of /path/sites/all/modules/contrib/search_api_solr/includes/service.inc).

I've trying stepping through all the code but there is just too much going on between search api, search api solr and views to find why this is occuring.

To replicate, have a site with many content types and many fields then create a solr view with 2 contextual filters, one can be content type, the other needs to be 'Search: More like this'.

I've supplied a patch with simply adds if (isset($fields[$f])) { inside the loop and this prevents the errors from occuring.

Comments

drunken monkey’s picture

Project: Search API Solr » Search API
Version: 7.x-1.6 » 7.x-1.x-dev
Component: Code » Views integration
Status: Active » Needs review
StatusFileSize
new1.03 KB

Thanks for reporting this issue!
I'd guess this comes from the fields selected in the "More like this" contextual filter not matching with the fields available in the index anymore (if fields were removed from the index after the filter was saved the last time).
To fix this, we should probably check for the existence of the fields right when adding them to the query, in the "More like this" Views handler.
The attached patch should do this. Please test it and see if it also resolves your problem!

Also, you seem relatively new to contributing (patches) on Drupal.org, so please let me give you a few tips for improving future contributions:

  • Please always keep to the Drupal coding standards when working on Drupal modules. In the case of the above patch, you used tabs for indenting and had a trailing space in one line.
  • Always create patches relative to the module directory – so, the file in the patch should be a/includes/service.inc, not a/all/modules/contrib/search_api_solr/includes/service.inc.
  • When posting a patch, please set the issue's status to "Needs review" so others know right away that there's already a patch. (Use "Needs work" if you post a patch that's not finished yet.)
drunken monkey’s picture

Could you please test the patch and verify it solves the problem for you?

drunken monkey’s picture

Title: Getting many notifications when using a view with mlt contextual fitler » Getting many notifications when using a view with mlt contextual filter
Status: Needs review » Fixed

  • drunken monkey committed d8dab1a on 7.x-1.x
    Issue #2447213 by drunken monkey: Fixed issues with stale field settings...

Status: Fixed » Closed (fixed)

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