Any way to show similar entries content in the form of a View?

fumbling - January 29, 2009 - 04:37
Project:Similar Entries
Version:6.x-1.1
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Any hope of pulling the same links shown in the Similar Entries block into a View? My apologies if this is a dupe, couldn't find any other Views-related threads using search.

#1

deekayen - January 29, 2009 - 05:28
Status:active» postponed (maintainer needs more info)

I'm having trouble imagining how that would work. Do you mean a similar nodes to the content of a view, similar views to the content of a view, or putting the content of the similar block into the content area of a node?

#2

fumbling - January 30, 2009 - 06:25

The last one, but in the form of a view: "putting the content of the similar block into the content area of a node" in the form of a view (using the view-block type).

#3

fumbling - February 11, 2009 - 12:22

Revisiting this one. I probably should have done a better job explaining. All in all, the essence of what I need is to surface similar entries content in a view. The rest will be straightforward. So is there any way you know of that I can create a view and using the relationship or arguments functionality pull in the same Similar Entries content that appears in the current block?

#4

artscoop - February 23, 2009 - 14:14

Hi, I am interested too in doing such a thing (Creating a view where we can filter nodes so that the list of Similar nodes can be retrieved)
As the module has not been updated in a bit less than a year, I thought I could try and integrate it to Views.
However, I'm a pure newbie, and the tutorials, yet simple, look helpless.

I keep you informed.

#5

fumbling - February 23, 2009 - 15:41

Thanks

#6

As If - April 1, 2009 - 13:41

Simple Nasty Hack:

STEP 1: Insert something like this into your node template:

$similarblock = similar_block('view', 0, $node);
if($similarblock['content']) {
  echo "<div class='similar'>";
    echo 'SIMILAR NODES<br>';
    echo $similarblock['content'];
  echo '</div>';
}

STEP 2: Open up similar.module in your text editor. Look for the function called similar_block(). You will see that there is no dedicated response to case "view". We are going to create one. First, copy the entire chunk of code for the default case. Then paste it in between the case "view" line and the default: line. Then replace the whole first if/else clause (i.e., 6 lines) with this single line: $node = $edit;. The result should look like this:

case 'view': // HACK BEGINS HERE
  $node = $edit;
  $similar_node_types = variable_get('similar_node_types', _similar_published_node_types());
  if ($node->nid > 0 && !empty($similar_node_types[$node->type])) {
  unset($similar_node_types);
  switch ($delta) {
    case 0:
    // The subject is displayed at the top of the block. Note that it should
    // be passed through t() for translation.
    $block['subject'] = t('Similar entries');
    $cache_blocks = variable_get('similar_cache', SIMILAR_CACHE_DISABLED);
    if ($cache_blocks) {
      $cached_content = cache_get("similar_block_0:$node->nid", 'cache');
      if ($cached_content === 0) { // cache_get() only returns 0 when data is not returned for the key
      $block['content'] = theme('similar_content', $node);
      $lifetime = variable_get('similar_cache_lifetime', SIMILAR_CACHE_LIFETIME);
      cache_set("similar_block_0:$node->nid", $block['content'], 'cache', $lifetime ? time() + $lifetime : CACHE_TEMPORARY);
      } else {
      $block['content'] = $cached_content->data;
      }
    } else {
      $block['content'] = theme('similar_content', $node);
    }
  }
  }
  return empty($block['content']) ? '' : $block;
  break;

default: // ORIGINAL CODE RESUMES HERE

NOTE: This is guaranteed to add load time and overhead to your view. This overhead could be significant on a page with many nodes, especially if the similar results for those nodes haven't been cached yet. But it works. YMMV.

#7

fumbling - April 7, 2009 - 18:07

Thanks, appreciate this.

#8

Flying Drupalist - May 8, 2009 - 16:15

Subscribe, a less expensive version would be nice.

#9

deekayen - May 8, 2009 - 16:22
Version:6.x-1.0» 6.x-1.1
Status:postponed (maintainer needs more info)» needs work

The custom similar caching code was removed in 6.x-1.1, so the above patch won't work.

#10

talatnat - November 9, 2009 - 12:00

A great module.

Is there any way of re-instituting Views support? The patch works very well, but can it be wrapped into a secondary module, so we can upgrade Similar Entries.

Note: Similar Entries plus the Views patch is the only way I know to show related content in a View. If there is any other way of handling this, I'd love to know.

 
 

Drupal is a registered trademark of Dries Buytaert.