Hi, I ran into the case where the default output of the mlt block is not sufficient and I had to display more fields from a node than just the title in the list output. I have overridden the theme function in my template.php to use a view mode that I defined using the Display Suite module. I thought it might help others if I posted the override I made here.

/**
 * Theme recommendation block generated by Apache Solr
 **/
function theme_apachesolr_mlt_recommendation_block($vars) {
  $docs = $vars['docs'];
  foreach ($docs as $result) {
    $node = node_load($result->entity_id);
    node_build_content($node, 'featured_teaser'); //'featured_teaser' is a custom view mode defined in Display Suite; I think normally only 'teaser', 'full', 'search_result' and 'search_index' are available
    $nodes[] = drupal_render($node->content);
  }
  return theme('item_list', array('items' => $nodes));
}

It might be a nice feature if the block would support view modes by default? The block configuration can still have the option to select a simple list output of titles and next to that an option to use a view mode (with a dropdown to select which view mode to use).

If I find time and it is something that people want, I could make a patch for it

CommentFileSizeAuthor
#7 1353422-7.patch1.11 KBnick_vh

Comments

nick_vh’s picture

Very interesting!

I'd prefer if this would be a build array so you would be easily able to change that with standard drupal hooks. Please go for a patch and we'll see where we can get from there :-)

nick_vh’s picture

Status: Active » Closed (duplicate)
nick_vh’s picture

Status: Closed (duplicate) » Active

Opening again, seems like it didn't make it into the issue from my previous comment. Let's make it happen in this issue

The problem resides in the fact that the module assumes it has to be in a list

function theme_apachesolr_search_mlt_recommendation_block($vars) {
  $docs = $vars['docs'];
  $links = array();
  foreach ($docs as $result) {
    // Suitable for single-site mode. Label is already safe.
    $links[] = l($result->label, $result->path, array('html' => TRUE));
  }
  return array(
    '#theme' => 'item_list',
    '#items' => $links,
  );
}

A possible solution could be that depending on the item we select a predefined view mode?
Any suggestions?

nick_vh’s picture

Status: Active » Needs work
nick_vh’s picture

Status: Needs work » Closed (won't fix)

Change this to a build array

$suggestions['content'] = theme('apachesolr_search_mlt_recommendation_block', array('docs' => $docs, 'delta' => $delta));
nick_vh’s picture

Status: Closed (won't fix) » Needs work
nick_vh’s picture

StatusFileSize
new1.11 KB

This should be sufficient for customized work. View modes is a difficult one because there is no clue for us to know what content will appear in the more like this block.

A theming function and a renderable array were added to accomodate for this possibility

nick_vh’s picture

Status: Needs work » Fixed

Committed

Status: Fixed » Closed (fixed)

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

dalin’s picture

So if we really wanted to make this configurable, the block settings form would show select fields for each type of entity with options for each view mode that the entity supports. The theme function would then check the entity type of each incoming document, and call the appropriate view function with the configured view mode. This would of course only work for things that are entities, but we could provide a fallback of just a link for those that are not.

stone_d’s picture

I stuck at the same point of theming the "more like this" output.

Since view modes are very good for theming the node-output, i think dalins apporach would be a good way of implementation. So thumbs up for this suggestion! It would be ok too, to just have one view-mode that the user would have to apply to the entity-type he needs ...

kopeboy’s picture

Version: 7.x-1.0-beta11 » 7.x-1.6
Issue summary: View changes
Status: Closed (fixed) » Active

Can we make this feature please? I think this is a major one, needed by many users who lack the skill to use custom php code

Khetam’s picture

This link also talk about create view mode for MLT block http://pingv.com/blog/improve-your-apache-solr-more-like-this-blocks