As it is written, this plugin seems to only return node results that actually have ANY of the tags of the nid passed in as similarbyterms.nid. I would like to sort by similar by terms, but not limit the results to only those with matching tags. Is there a way to do this? In other words, I want ALL nodes included as part of my view, but still want to sort by similar, without limiting those results to only nodes with any matching tags. Those with no matches, are still inlcuded, just at the bottom of the list since they don't match at all....

Comments

jjeff’s picture

Title: Sort by Similar only returns nodes that match tags » Add non-matching nodes to results
Status: Active » Postponed

Unfortunately, there's not an easy way to do this. Here's a typical SQL query for the default SBT2 view:

SELECT node.nid AS nid, node.title AS node_title,
COUNT(node.nid) AS node_count 
FROM node node  
LEFT JOIN term_node term_node ON node.vid = term_node.vid 
WHERE (node.moderate = 0) AND (node.status <> 0) AND (term_node.tid IN (139, 84, 140, 48, 74, 8)) AND (node.nid != 36) 
GROUP BY nid, node_title 
ORDER BY node_count DESC

Note the part that says term_node.tid IN (139, 84, 140, 48, 74, 8)

This basically says, "find other nodes with the same terms as those associated with this node." And the combination of the COUNT(node.nid) and the GROUP BY nid provides the sorting functionality. Unfortunately, there's not a way that I'm aware of to include nodes which don't match this criteria while still allowing us to sort/view by similarity.

If anyone knows of a way to make this work, I'm open to it. It's just beyond my understanding at this point.

Big Z’s picture

I was looking for this exact functionality. After thinking for a while I decided to spin the problem on its head and attack it from the taxonomy side.

Using the Taxonomy Defaults module you can give every node you create a default (hidden) term. This has no affect on the ordering produced by the SBT sort, but does include every node!

The only problem is nodes that already exist need to be updated to include the default term. Maybe a bulk update utility exists out there or a simple update query could be run on the term_node table.

Hope this helps.

Professional Drupal Development
www.vitalatus.co.uk

takim’s picture

Issue summary: View changes
Status: Postponed » Closed (won't fix)