Received this notice when viewing a page with an apachesole more like this (MLT) block on it:

Notice: Undefined index: page_id in apachesolr_multilingual_apachesolr_query_alter() (line 402 of /var/www/mts/sites/all/modules/contrib/apachesolr_multilingual/apachesolr_multilingual.module).

The line in question is:

$search_page = apachesolr_search_page_load($context['page_id']);

MLT blocks do not have a page_id, they have a block_id, for instance, this is mine:

block_id (String, 7 characters ) mlt-002

Patch attached in the next comment to allow the query alter on pages only (so the query alter will not run on MLT blocks).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wiifm’s picture

Status: Active » Needs review
FileSize
720 bytes

Patch attached.

imoreno’s picture

patch in #1 Did the job for me.
error message is gone.

BR
Itzhak

mkalkbrenner’s picture

Status: Needs review » Needs work

The patch turns off the multilingual query altering for MLT blocks in general. That's ok as long as a MLT block is configured to work on non-text fields. But for text fields we probably have to fix and modify the altering.

mkalkbrenner’s picture

Title: Notice: Undefined index: page_id in apachesolr_multilingual_apachesolr_query_alter() » More like this (MLT): Undefined index: page_id in apachesolr_multilingual_apachesolr_query_alter()
Issue summary: View changes
yaronmiro’s picture

Patch in #1 won't work if the page belongs to Views as there is no $context['page_id'], but other values exist.

I suggest adding something like $context['page_id'] = !empty($context['page_id']) ? $context['page_id'] : 'views';

Patch will follow.

yaronmiro’s picture

Status: Needs work » Needs review
FileSize
770 bytes
mkalkbrenner’s picture

Status: Needs review » Needs work

@yaronmiro: The views issue is not related to MLT.

The views issue is a bug in Apache Solr VIews itself that is somewhat outdated. They did not catch up with an API change within the Apache Solr module. I posted a patch there:

#1969268: Broken compatibility with DrupalSolrQueryInterface causes Apache Solr Multilingual to fail (Undefined index: page_id)

yngens2’s picture

The patch in #1 cause the "More like this block" to start outputting links to the nodes in other languages. The patch in #6 did the job.

danielkutik’s picture

Similar issue:

Notice: Undefined index: page_id in apachesolr_multilingual_apachesolr_query_alter() (line 479 of C:\htdocs\www.tec-tus.de\www\sites\all\modules\apachesolr_multilingual\apachesolr_multilingual.module).
    //line 479
    $filter_languages = &drupal_static('apachesolr_multilingual_filter_languages_' . $context['page_id']);

  • Commit 6591ee0 on 7.x-1.x by mkalkbrenner:
    [#2056055] mkalkbrenner: More like this (MLT): Avoid Undefined index:...
mkalkbrenner’s picture

Title: More like this (MLT): Undefined index: page_id in apachesolr_multilingual_apachesolr_query_alter() » Provide multilingual settings for More like this (MLT)
Category: Bug report » Feature request

I committed a first patch that avoids these warnings for MLT and Views:
http://drupalcode.org/project/apachesolr_multilingual.git/commit/6591ee0

But as I stated in #3 and as TODO in the comments in the source code, the final solution for this issue looks different.
With the last commit we apply the default multilingual settings to MLT, like yaronmiro did in his patch. But instead applying the defaults we need to add multilingual settings to the MLT block configuration like we do for search pages.

  • Commit ace8f99 on 7.x-1.x by mkalkbrenner:
    [#2056055] mkalkbrenner: Provide multilingual settings for More like...
mkalkbrenner’s picture

Assigned: Unassigned » mkalkbrenner
Status: Needs work » Needs review

I committed a first version of configurable multilingual MLT blocks:
http://drupalcode.org/project/apachesolr_multilingual.git/commit/ace8f99

Anyone who can test this?

BTW the "error" described in #8 is now configurable by "Limit search to current language by default".

mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

  • Commit 6591ee0 on 7.x-1.x, 6.x-3.x by mkalkbrenner:
    [#2056055] mkalkbrenner: More like this (MLT): Avoid Undefined index:...
  • Commit ace8f99 on 7.x-1.x, 6.x-3.x by mkalkbrenner:
    [#2056055] mkalkbrenner: Provide multilingual settings for More like...
BarisW’s picture

Status: Closed (fixed) » Active

The issue in #9 is still valid with the current DEV.

mkalkbrenner’s picture

Status: Active » Needs review
FileSize
939 bytes

I already committed this patch to git. Does it fix #9?

  • Commit cf2f5e6 on 7.x-1.x by mkalkbrenner:
    Issue #2056055 by mkalkbrenner: fixed remaining issue on mlt blocks
    
BarisW’s picture

Status: Needs review » Closed (fixed)

Yes, thanks! A new pull from git fixes the issue :)

mkalkbrenner’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Closed (fixed) » Patch (to be ported)

  • Commit 6f8f547 on 6.x-3.x by mkalkbrenner:
    Issue #2056055 by mkalkbrenner: fixed remaining issue on mlt blocks
    
mkalkbrenner’s picture

Status: Patch (to be ported) » Fixed
ricardoj.m.pinto@gmail.com’s picture

mkalkbrenner, is this patch available to 7.x-1.0 ? Thanks.

mkalkbrenner’s picture

See comments #18 and #19. The patch has been committed to 7.x-1.x-dev already.

Status: Fixed » Closed (fixed)

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

partdigital’s picture

I was able to reproduce this issue when I used the apachesolr panels module. Please see my comments (and patch) here:
https://www.drupal.org/node/2315731#comment-9251217