Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm getting this error:
Warning: implode() [function.implode]: Invalid arguments passed in theme_apachesolr_search_snippets() (line 1708 of /Applications/MAMP/html/MY_SITE/sites/all/modules/apachesolr/apachesolr_search.module).
Comment | File | Size | Author |
---|---|---|---|
#35 | 1946132-D6-35.patch | 2.22 KB | jantoine |
#34 | 1946132-D6-34.patch | 2.22 KB | jantoine |
#32 | 1946132-D6-32.patch | 2.08 KB | jantoine |
#31 | 1946132-D6-31.patch | 2.17 KB | pwolanin |
#28 | apachesolr-snippets-d6-1946132-28.patch | 1.85 KB | jantoine |
Comments
Comment #1
justluvgod CreditAttribution: justluvgod commentedsame here. I am using 3.6.2 version of Apache SOLR
Comment #2
Nick_vhI've seen this happen also.
Replace
$result .= implode(' ... ', $snippet);
With
Comment #3
justluvgod CreditAttribution: justluvgod commentedthanks will give it a quick try and let you know the results.
Comment #4
justluvgod CreditAttribution: justluvgod commentedThanks that seemed to work perfectly. I had to remove one of the closing brackets but no errors thus far.
foreach ($snippets as $snippet) {
/* this is new code added for drupal issue #1946132*/
if (is_array($snippet)) {
$result .= implode(' ... ', $snippet);
}
}
/*END this is new code added for drupal issue #1946132*/
$result .= implode(' ... ', $snippets);
/*} **removed closing bracket*/
}
}
return $result . ' ...';
}
thanks again. Any chance you are writing a tutorial integrating TIKA with SOLR? Your tutorials have been really helpful.
Comment #5
mkalkbrennerI created a patch to solve that issue.
But I didn't like the code and choose a different approach now. I flatten the complete snippet array and avoid the warnings, allow configuration of max snippets and avoid duplicate snippets.
Comment #6
Nick_vhI don't like that change. If someone wants to change it so drastically they can, it is a theme function afterall.
Can it not be done simpler?
Comment #7
mkalkbrennerThis patch solved three issues:
In our production environment we've often seen case 2 and 3. (BTW both are not multilingual related.)
Since we applied the patch, the results look way better.
In addition I added a new feature to limit the over all number of snippets by configuration.
What exactly don't you like?
From my point of view the code does basically the same: walking through the snippet arrays and concatenate the snippets using " ... ". But it's done in a generic way instead of an erroneous manual way.
What makes the code look a bit scary maybe is the safety stuff to prevent endless loops, but that's a normal pattern.
Comment #8
JmOkay CreditAttribution: JmOkay commentedThe patch worked for me: 1946132.patch
Thanks Nick_vh & mkalkbrenner
Comment #9
deja711 CreditAttribution: deja711 commentedGot the same issue, and this patched worked for me as well (1946132.patch).
Thanks guys. I am guessing this will make it to next 7.x-1.3 version?
Comment #10
wiifm+1 for this to be committed, the dblog was filling up with useless warnings relating to this, the patch attached resolved said warnings.
Comment #11
acbramley CreditAttribution: acbramley commented+1 RTBC, after module upgrade my watchdog was filled with these warnings, patch fixed all warnings.
Comment #12
Gold+1 for this to be committed. #10 & #11 are not wrong about the flood in watchdog.
Comment #13
pwolanin CreditAttribution: pwolanin commentedSeems a little heavy to be doing in the theme function in any case - can we shift to a preprocess?
Comment #14
japerryThere are some odd problems with how these snippets are being displayed, but for now this patch should fix the issue with this specific error message.
Comment #15
David_Rothstein CreditAttribution: David_Rothstein commentedThat doesn't look right either, since I think each element of $snippets can still sometimes be an array itself, rather than a string?
Seems like it makes sense to improve this logic and move it to a preprocess function like @pwolanin suggested. That would also allow it to be reused in other modules (for example, #1980750: Array to String error when certain file attachments appear in the search results in the Apache Solr Attachments module which is a similar bug).
The attached patch tries to do this.
Comment #16
pwolanin CreditAttribution: pwolanin commentedSo, I'd suggest maybe the last line of the preprocess still belongs in the theme function?
Comment #17
acbramley CreditAttribution: acbramley commentedAgree with #16
Comment #18
wiifmSo patch #15 fails to address to root problem here that patch #5 did. After getting 7.x-1.x-dev and applying patch #15:
Notice: Undefined index: snippet in theme_apachesolr_search_snippets() (line 1715 of /var/www/mts/sites/all/modules/contrib/apachesolr/apachesolr_search.module).
Backtrace is here:
Comment #19
David_Rothstein CreditAttribution: David_Rothstein commented@wiifm, did you clear caches after applying the patch?
Comment #20
David_Rothstein CreditAttribution: David_Rothstein commentedThat could definitely work, but the reason I didn't do it that way originally was:
Comment #21
mkalkbrennerUnlike my patch in #5 the patch in #15 doesn't remove duplicates.
Duplicates happen very often when the teaser contains the first n characters of the body (or content).
Comment #22
jantoine CreditAttribution: jantoine commentedAgree with #16 as well. Also tagging for backport.
Comment #23
wiifm@David_Rothstein - hey, thanks, after clearing the cache, the errors went away.
+1 for #15 to be committed.
Comment #24
mkalkbrennerSeems like most people prefer #15 instead #5 ;-)
So here's an adjusted version of patch #15 that
- ensures that the snippets contain no duplicates
- respects Peter's suggestion in #16 regarding the theme function
- keeps the unmodified $vars['snippets'] for backwards compatibility in existing themes
Comment #25
jantoine CreditAttribution: jantoine commented#24 is solid. Please commit!
Comment #26
wiifmAgree, +1 on #24. It makes sense to keep any markup generated in theme functions.
Comment #27
David_Rothstein CreditAttribution: David_Rothstein commentedThanks for adding the array_unique(), @mkalkbrenner. Sorry I missed that.
I've posted an updated patch at #1980750-7: Array to String error when certain file attachments appear in the search results to work with the new patch in #24 here.
Comment #28
jantoine CreditAttribution: jantoine commentedHere is a shot at a D6 backport. To avoid adding a template file, I had to merge the preprocess and theme functions back together per this issue: #400292: Allow preprocess functions for theme hooks implemented as functions. Patch attached.
Comment #30
David_Rothstein CreditAttribution: David_Rothstein commented#24 is the RTBC patch.
Comment #31
pwolanin CreditAttribution: pwolanin commentedFor 6.x, perhaps we should keep the separate " preprocess" function, but just call it directly from the theme function, or before the theme function?
For 7.x, this is in essence an API change because it's a different variable name? I guess that's ok.
Committed to 7.x. Here's a revised backport.
Comment #32
jantoine CreditAttribution: jantoine commentedI like the motivation behind the patch in #31 for keeping the functions separate. I was however, receiving the following error with the patch applied:
I made the following changes to fix this error and make the code a little more readable:
If the goal is to keep the code as close to D7 as possible, we could undo my changes and simply replace the first array_merge() call found within the foreach loop with similar syntax found in the second array_merge() call used within the function:
Comment #33
pwolanin CreditAttribution: pwolanin commentedThanks for the fixes.
I was trying to keep it as close to 7.x as possible to make it easier to backport any further patches. Can you roll it that way?
Comment #34
jantoine CreditAttribution: jantoine commentedOK, new patch attached only changed the first array_merge to ensure we are merging arrays!
Comment #35
jantoine CreditAttribution: jantoine commentedFixed typo in variable name in patch from #34.
Comment #37
pwolanin CreditAttribution: pwolanin commented#35: 1946132-D6-35.patch queued for re-testing.
Comment #38
dbolser CreditAttribution: dbolser commentedHi, sorry for ignorance, but is this patch available for 7.x-1.3? I'm seeing this error in abundance.
Many thanks,
Dan.
Comment #39
mkalkbrenner@dbolser: #24 should already be included in 7.x-1.3. Do you still see the error?
Comment #40
dbolser CreditAttribution: dbolser commentedDang... Just updated, and I'm guessing this was a caching issue! Seems fine now!
Many thanks,
Dan.
Comment #41
pwolanin CreditAttribution: pwolanin commentedcommitted
Comment #43
hideaway CreditAttribution: hideaway commentedI still see the error with latest 7.26 Drupal, Apache Solr 7.x-1.6 and Apachesolr Views 7.x-1.0-beta2.
I don't quite understand WHY the 1716 is like this:
and line 1709 is like:
In my case I get snippets array not multidimensional but like $snippets['content'] = 'snippet'. The change condition of array merge fixed everything: