Great module, instant easy failsafe blocks that add tons to a site.

A views block would be exponentially awesome with map blocks of content similar by terms and image grids. Less mindbending than arguments, better than endless snippets.

There are probably many more uses and probably a few icebergs that I haven't seen. Would it take a lot to do it?

Thanks again for SBT and your many other drupal blessings

R3

Comments

rmiddle’s picture

Title: Similar by Terms View ... for maps, images and stuff » Integrate with Views Module

This is something that jeff wants to get done and I think it would be useful as well. Leaving it open.

David Lesieur’s picture

You might want to have a look at the Similar Nodes module.

rup3rt’s picture

Thanks David,

I am looking!

R3

giorgio79’s picture

Any timeplans? :)

rmiddle’s picture

No time frame at this point. I am looking into what it takes to add views into a module but nothing at this point.

Thanks

xvx’s picture

Similar Nodes does not work with blocks properly, there is a support request in, but according to another post, that projects has been abandoned.

giorgio79’s picture

Meanwhile I was trying to get a related content block view going with this description here http://drupal.org/node/65375 but no luck yet

giorgio79’s picture

I realise this module can show teasers, and we can define CCK teasers with contemplate oh jeah. Will try that out now

rmiddle’s picture

The theme function is given a full node you can overide that display and make it look however you want. I am open to patches as well if you need added support.

Thanks
Robert

giorgio79’s picture

Yes I saw that...Unfortunately the teaser for the CCK comes out as empty even with contemplate and the cck teaser module, so I am thinking of taking out the entire similarterms_list function, modding it so I get an array of node ids and passing it into a view as an argument handling code,

This way I can build a view on node ids as arguments...

I am not sure how to do patches,but this seems to be the quickest for me now :) I am a bit fed up with the cck teaser stuff.

rmiddle’s picture

Well once you are done post the code I will look at it and see if I can incorpate what you wrote with Similar by Terms.

Thanks
Robert

giorgio79’s picture

Hello Robert,

Here we go...

It is not a patch, more of a rip :) loller

I took this code straight from the module, modded the end so it shoves all the nodeids in an array and passed this as an argument handling code into a view.

I set the argument to Node ID with Display All Fields options...

Lo and behold, I got my related view block up in no second :D Sorry for ripping your code, but views is views after all :D

  $nodes = array();

  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
  }
  if ($nid != NULL) {
    $full_node = node_load($nid);
    if ($vocid == 0) {
      $terms = array_keys(taxonomy_node_get_terms($full_node->nid));
    }
    else {
      $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($full_node->nid, $vocid));
    }
    // Filter out some terms
    $terms_filter = variable_get('simterms_ignoreterms_'. $vocid, array());
    for ($i = 0; $i < count($terms_filter); $i++) {
      $idx = array_search($terms_filter[$i], $terms);
      if ($idx >= 0) {
        unset($terms[$idx]);
      }
    }
    $terms = implode(',', $terms);
    $count = variable_get('simterms_count_'. $vocid, 5);
    if (!empty($terms)) {
      //past events
      $pasts = array();
      $types = variable_get('simterms_sametype_'. $vocid, false);
      if (($types !== false) && is_array($types) && ($types['0'] == NULL) ) {
        if ($types[1]) {
          $node_obj = node_load($nid);
          $types[1] = $node_obj->type;
        }
        $str_types = "'". implode("','", $types) ."'"; // couldnt find a solutin for IN %s problem and \' substi
        $sql = sprintf(
          'SELECT n.nid, n.title, COUNT(n.nid) AS ncount '.
            'FROM {node} n '.
            'INNER JOIN {term_node} tn ON n.nid = tn.nid '.
            'WHERE tn.tid IN (%s) '.
            'AND n.type IN ('. $str_types .') '.
            'AND n.nid != %d '.
            'AND n.status = 1 '.
            'AND n.moderate = 0 '.
            'GROUP BY n.nid, n.title, n.created '.
            'ORDER BY ncount DESC, n.created DESC '.
            'LIMIT %d',
          $terms, $nid, $count);
      }
      else {
        $sql = sprintf(
          'SELECT n.nid, n.title, COUNT(n.nid) AS ncount '.
            'FROM {node} n '.
            'INNER JOIN {term_node} tn ON n.nid = tn.nid '.
            'WHERE tn.tid IN (%s) '.
            'AND n.nid != %d '.
            'AND n.status = 1 '.
            'AND n.moderate = 0 '.
            'GROUP BY n.nid, n.title, n.created '.
            'ORDER BY ncount DESC, n.created DESC '.
            'LIMIT %d',
          $terms, $nid, $count);
      }
      $sql = db_rewrite_sql($sql);
      $result = db_query($sql);
      while ($r = db_fetch_object($result)) {
        $nodes[] = $r->nid;
      }
    }
  }
  
//	print ('<pre>');
//	print_r ($nodes);
//	print ('<post>');
 

  if($nodes){
    return array(implode('+', $nodes)); //include current node, so we can skip it
  }


giorgio79’s picture

I have put this in production, and have been observing my mysql process from shell with "mysqladmin processlist -i 2" and can confirm that I get a massive amount of file write to dis by this query:

converting HEAP to MyISAM | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....
Copying to tmp table | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....
Copying to tmp table on disk | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....

Probably this is not related to my solution, but the general query...

rmiddle’s picture

giorgio79,

Sounds like it. The block gets cached when it displays and doesn't rerun the query it is possible that there is no caching happening with your mod.

Thanks
Robert

dropchew’s picture

Looking forward to this feature. subscribing

mroswell’s picture

subscribe

dropchew’s picture

This is something like 'relatedviews' except RV is lacking multiple terms support. Whereas SBT is lacking in views support. Hope someone can integrate the 2...

michellezeedru’s picture

Subscribing - would also like views integration. For example, I want to control the order of the terms, and the number of results that display. Is there another way to do this that I'm overlooking? Thanks for the module!

rmiddle’s picture

mziegmann,

Number of results is controllable in block config. Order of the terms would require an SQL change.

Thanks
Robert

rmiddle’s picture

I really need to add views support into this module. I have a few two many other things I need to get finished 1st.

Thanks
Robert

talatnat’s picture

+1 subscribing.

Is there any "Similar" or "Related" modules with Views 2 support?

rmiddle’s picture

talatnat,

No idea if there is. I plan to add views2 support at some point but not sure when right now.

Thanks
Robert

talatnat’s picture

Robert: Took a closer look and the Similarity module is in dev, and has Views support. I wonder if the Views code can be pulled in here?

Talatnat

Flying Drupalist’s picture

Can this become a patch for 6.x please?

rmiddle’s picture

Version: 5.x-1.x-dev » 6.x-1.18

Moving this to 6.x since this feature likely wont make it into hte 5.x version.

Thanks
Robert

calte’s picture

Sub/+1

BeaPower’s picture

any update>?

feuillet’s picture

subscribing

Would love to see views integration here to customize the output with the power of views (e.g. slideshows etc.)

rmiddle’s picture

I have looked at views a few times but couldn't really make heads or tails out of the documentation for views. If someone writes the interface I will for certain use it. Maybe once I get some of my Drupal 7 Modules ready I will try again to integrate into views.

Thanks
Robert

jjeff’s picture

I've been experimenting with some code to do exactly this: a Views-based rewrite of Similar By Terms. I just wrote the code this weekend and haven't had a chance to test it out extensively or contribute it back to Drupal.org. But it's working fine on my test setup. It's still in flux and I may rework its functionality, so consider it to be alpha code.

Test it out and let me know what you think: http://github.com/Lullabot/similarstuff

-Jeff Robbins
Lullabot

rmiddle’s picture

Jeff,

Are you planing on creating a new project or merging it back in Similar By Terms?

Thanks
Robert

jjeff’s picture

I hadn't really thought it out that far. I guess I didn't want to step on anyone's toes so I thought it might be a separate project. But on further thought it seems like Similar Stuff module would essentially supersede the functionality of Similar By Terms. So maybe we should consider turning Similar Stuff into the 2.x version of Similar By Terms.

It's a complete ground-up rewrite of the module. But since Similar By Terms is installed on 4,000 websites, maybe we shouldn't expect everyone to move from one project to the other.

However, I don't really see how we would implement any sort of an upgrade path. If we do this, admins will need to re-create their blocks when moving from 1.x to 2.x.

Thoughts?

rmiddle’s picture

Jeff,

Well looking at the code for the most part we could combine the projects into 1 version. That includes the existing block code plus add views support. The main area of overlap is the SQL query the true brains of the module and the reason it is so useful. We can work inside github if you want to or I could add you back in as a co-maintainer and work from CVS. I use both although I use git more now on a day to day bases.

Thanks
Robert

damiandab’s picture

Assigned: Unassigned » damiandab

subscribing

damiandab’s picture

Assigned: damiandab » Unassigned
feuillet’s picture

Test it out and let me know what you think: http://github.com/Lullabot/similarstuff

Thank you very much, works like a charm here!

the only feature i miss is to define a particular vocabulary on wich the similarity should be calculated on, that would make it perfect!

Best Regards,
Sandro

jjeff’s picture

It's on the to-do list! Should have that working in a few days.

calte’s picture

Awesome! Thanks Jeff!

pixelsweatshop’s picture

subscribing

jjeff’s picture

Title: Integrate with Views Module » Create Similar By Terms 2.0 as a Views plug-in

Just wanted to leave a note and say that over the weekend, I did a bunch of work on Similar Stuff and it's now basically on par with Similar By Terms. The current plan is that Similar Stuff will become Similar By Terms 2.0. I just need to tweak the default View a bit and then do a search/replace to change the name of the module.

Features I added over the weekend:
- Allow limiting similarity to specific vocabularies
- Allow passing in of multiple nodes so you can say "Here's similar stuff to these nodes"
- Added "don't show this node in results" checkbox to nid argument section - so you can show the argument node(s) in the listing.
- Created a displayable field which shows the % of similarity
- More/better README content

http://github.com/Lullabot/similarstuff

Anyone want to look into getting Similar Stuff to work in Drupal 7 (and/or Views 3)? I haven't spent any time on that. The whole module is just a Views plug-in. It might "just work".

jjeff’s picture

Status: Active » Needs review

Similar By Terms 2 is ready to roll!

I've got it all set up over at http://github.com/jjeff/similarterms

Robert, if you're okay with it, I'll create a 2.x branch and add it into CVS. We should probably do it as a beta release to let people test it out before doing a proper 2.x release.

Note that there's also no upgrade path, and we might even want to create a .install file to remove the old Similar By Terms 1.x database table.

jthomasbailey’s picture

Hey Jeff, I installed Similar By Terms 2 but don't see the view or block it was supposed to create. Using Views 3.x-dev.

jjeff’s picture

Well that shouldn't hold up the release at all. Views 3 is still in alpha. It works fine with Views 2.

jjeff’s picture

Status: Needs review » Fixed

Code is committed to the 2.x branch and an alpha release has been created.

Please download, try it out, and create new issues if you find problems.

Marking this issue as fixed.

Status: Fixed » Closed (fixed)

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

fourmi4x’s picture

No problem so far with views 3 for me...