The views integration of 'Similar By Terms' allows to output the calculated similarity in views with a field; in one view i just built, these fields output bizarre similarity values like "1300%", "480%", "400%", "280%" etc. This is quite irritating for users since nobody understands what this is supposed to mean.
I'm no math guru, but I'd guess that a complete match of all terms should be "100%" similarity, if less than all terms match, a value below 100% should be calculated; I can't imagine a valid scenario where "1300%" similarity would make any sense. So maybe there is a flaw somewhere is the code.
Configuration of the Views field: "Show as percentage", "Append % when showing percentage".
Also I tried to switch from "Show as percentage" to "Show count of common terms"; this outputs strange figures as well; e.g. I'm getting the number "65" (count of common terms!) for a node which has just 11 terms (from which only 3 should be evaluated according to the argument's settings).
The site is live and I can point out some links if this would help. This is not a major issue since the calculated nodes by similarity seem to be (more or less) correct, but it is really irritating for users, and it confuses me the more I try to understand it.
Thanks & greetings,
-asb
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | similar-movies_views-3-export.txt | 59.51 KB | asb |
| #1 | similarterms.node_count.patch | 654 bytes | brad.bulger |
Comments
Comment #1
brad.bulger commentedthis patch corrects the count - it adds DISTINCT - but i don't know if that is MySQL specific or not. i also wonder if it is just masking some other issue, as i am not sure why i was getting duplicate node entries in the first place.
Comment #2
asb commentedThanks for the patch, but it doesn't apply to similarterms 6.x-2.2. I'll upgrade to similarterms 6.x-2.x-dev and try again...
Edit: Doesn't work for me, either. Neither with nor without
-p0(patch is in./sites/all/modules/similarterms).Comment #3
brad.bulger commentedi am running 6.x-2.2. ah, i built it in the views directory, that's probably the problem. apply it specifically to similarterms/views/similarterms_handler_sort_similar.inc
i'll redo it and reupload soon.
Comment #4
jjeff commentedI believe that adding DISTINCT will stop the sort from working at all. Having GROUPed multiple nids is kind of the whole trick to SBT2. If my understanding of SQL is correct (and it might not be), DISTINCT will effectively cancel out the GROUP function and all similar nodes will sort as 100% similar. It may appear that things are working, but you may end up with sortings which appear to be out of order.
For example:
100%
58%
78%
97%
I'll need to do some experimenting and research to see if my hunch is correct on this though.
But in short, my gut feeling is that adding DISTINCT is not the right fix here.
Comment #5
jjeff commentedSo much for my gut. The further I'm looking into this, the more DISTINCT looks like it might be the right way to go. Still need to do some more experimenting though.
Comment #6
brad.bulger commentedi think you're right - i went off on the wrong track because my view's query was already doing a DISTINCT for other reasons.
but returning 200% is wrong, too. it may be that node IDs are the wrong things to be counting to begin with. the percentage math is comparing that count to
$this->view->tidswhich is a count of the unique term IDs for the argument node(s). so maybe COUNT(DISTINCT term_node.tid) would be right. i have to do more testing to check that.for the SQL, though, count(distinct field) runs within the grouping, just as count(field) does - it doesn't cancel it or override it, it just gives you a different result: within group A, there are X total values and Y distinct ones.
Comment #7
summit commentedSubscribing, greetings, Martijn
Comment #8
dhigby commentedI have the same issue, but not only is the percentage wrong (1000% give or take a hundred), only one similar term is displayed where there used to be several. In fact, there should be 5 similar terms showing for each node, but now there is only one, and it seems to be the same node for each node.
Since this is a production site, I'd be happy to downgrade, but don't know at what point this was last working correctly. Seems to me it was working fine a month ago.
Possible factors:
I am using the dev version of Views.
I recently upgraded to PHP 5.3
Comment #9
fourmi4x commentedSuscribing, I have the same issue: only a single result, displaying similarities such as 1500%, 400%... !! Using the 6.x-2.x version.
EDIT: I'm also using views 3 . I tried downgrading to the versions 2.2, and 2.0-rc1, but couldn't get it to work.
I think this might simply come from an incompatibility with views 3... ?? An issue about that (http://drupal.org/node/1181566) was left unanswered.
Comment #10
asb commentedNope, this has nothind to do with the dev release of Views. The described behaviour occurs like this for a couple of months with Views2 as well.
Comment #11
fourmi4x commentedI've found a temporary workaround: with views 3, enable the Group By option on the view, and create a field on nid grouped on SUM for instance. ("SUM(Node: Nid) Nid").
I then get all results and the right percentages.
Comment #12
dhigby commentedThanks fourmi4x, you're a genious! I have no idea why it works, but I've had this cool feature disabled for 6 months now and was happy to turn it back on.
Comment #13
joachim commented> I think this might simply come from an incompatibility with views 3
Sounds right to me. Aggregate queries are completely different on Views 3.
Comment #14
asb commented@joachim: Nope, this issue has nothing to do with Views 3, it already existed with Views 2.
However, Similar By Terms has several other issues with Views 3, and the wrong "Similarity" calculations exist under Views 3 as well.
Comment #15
joachim commentedCan anyone give examples of the node and term combinations that are producing the error? Can you whittle it down to a result set of maybe just one subject node and one result node so we can figure it out?
The multiple rows come from the join to {term_node} with a WHERE clause on multiple term tids, but there are never more tids than on the subject node -- and hence the number of duplicate rows will never be larger than that. Or at least in the cases I am considering!
Comment #16
asb commentedMaybe others can jump in here since my setups are pretty complicated to replicate.
In case nobody can provide something more straight-forward, I'd suggest to look into Views 3 since joachim seems to have some suspicions and most of us will move to Views 3 in the near future anyway. Based on my two Views 3 setups with unpatched CCK, I'd suggest the following procedure to reproduce: Build a content type with an ASIN field and a tags vocabulary, put a relationship on this field and pull some data from amazon by using this field. If you do this, you will get similarity values like 160% (example: similar movies like "An Affair to Remember", http://cinedat.org/similar/movies/7636; in the tabular listing, similarity values are given in the column "Übereinstimmung" with the number of matching tags and a percentage value).
If you remove the relationship on the ASIN field, you'll get a slightly different set of results, but "sane" similarity values like "20%" (example: http://cinedat.org/node/7636, similar movies block on the right; similarity values are given like this: "Übereinstimmung: 20%"; sorry, this site is in German).
I believe (= gut feeling) that the relationship itself confuses the similarity calculation, not the ASIN field or Views 3 issues with CCK; probably you'd get similar results with a relationship an any other multi-value field, but I haven't tried this.
In case you want to replicate the setup, I'm attaching the view I'm using; it produces a Views page at
./similar/moviesand provides a "similar content" type block.Comment #17
joachim commented> probably you'd get similar results with a relationship an any other multi-value field
Oh yes, that makes sense.
Suppose we have our subject node with terms X and Y, and we have these nodes to list:
A: X
B: Y
C: X, Y
The rows from the query without the grouping will be:
A
B
C
C
C appears twice because it has both terms and the join to term_node intentionally causes that. The COUNT then gives us:
A: 1
B: 1
C: 2
Percent match is calculated by taking the proportion of the terms on the initial node, and there were two (though see #1401164: documentation should explain similarity is not reflexive).
So we get:
A: 50%
B: 50%
C: 100%
Now if your query has other joins that cause say node A to get more rows based on something completely different, then yes, you're going to get totally wacky percentages. Say node A produces 6 rows in total. 6/2 is 3, so it will show 300%.
I'm afraid the only fix is probably 'don't do that', or 'make sure your relationship doesn't multiply rows'.
There might be some mileage in adding the satisfying term to the query results and then doing COUNT DISTINCT on it maybe? But it's MySQL-specific AFAICT and it's going to cause all sorts of pain come Views 3.
Comment #18
asb commented@joachim (#17): That's exactly what I suspected. However, a "don't do that" wouldn't be too too great, wouldn't it ;)
Regarding the suggested workaround from #11 I can only say that this does not work for my setup. As far as I understand the DISTINCT/GROUP BY ramifications, this is only a workaround to mimic the behaviour of the DISTINCT operator from Views 2 (cf. #1234048: Distinct requires workaround with bad usability to make 6.x-3.x-dev work like Views 2 with in-depth technical explanation in #11). The DISTINCT operator from Views 3 works different (or does not work at all, at least it does not for me, and supposedly can not work in views-7.x-3.x as DBTNG does not even support DISTINCT, cf. #863478: Distinct is not supported by dbtng), and Views built on Views 2 that are run under Views 3 tend to produce duplicates, even with "DISTICT" enabled; the workaround from #11 fixes that. However, in my case I had no duplicates, and the GROUP BY on Node:NID does not fix the wrong similarity amount/percentage calculations.
#1401164: documentation should explain similarity is not reflexive is an incredible interesting issue since I have some doubts that this module even calculates the similarity correctly. At least judging from my real-world data, I frequently get similarity candidates that are not plausible if I manually compare the terms from the evaluated vocabularies. However, it's virtually impossible to tell for sure if the number of matching tags ifs calculated wrong (so I have no proper value to compare), and the module does not allow to print the matching terms it has based it's decision on. However, this would be a related, but different issue.
Regarding the calculation of similarity amounts/percentages under Views 3, several other issues might interfer:
Pointers:
Honestly I have serious problems to mentally grok the interplay between DISTINCT, GROUPBY, and any calculations on top of this. E.g., wouldn't any calculation have to either work with the not-unique (complete) result set (including "duplicates"), or the unique (sub-) set (without duplicates)?
Comment #19
joachim commented> this is only a workaround to mimic the behaviour of the DISTINCT operator from Views 2
This isn't about the DISTINCT operator that affects the whole query (ie, the 'SELECT DISTINCT ...').
This is a different beast.
Here's an illustration of the problem.
Suppose this is our result set *without* any aggregation (well, pseudo-result set; I'm using letters rather than numbers to make it easier to read).
We have two subject terms, X and Y, and three nodes in the result. The columns are nodes, terms, and an extra column from the join (the only important thing in that column is that there are different values).
- Node C produces only one row because it has only one term.
- Node B is correctly producing two rows because it has both terms.
- Node A has *three* rows because the extra join is giving us three different values for A (hmm or would that be 6? I'm using dummy data here rather than try to replicate the circumstances in my database). This is causing the result for node A to have *three* rows even though it only has *two* terms.
Here's the result set with aggregation:
The COUNT(term) column, which is what the module currently uses, is giving us the wrong answer for node A: similarity rating is 3, when there are only two terms!
The COUNT(DISTINCT term) column is counting how many distinct values for the term there are for this current aggregated row. In other words, 'How many different terms are listed for node A?'. This gives 2, which is the answer we want.
What this raises:
- what are the performance implications of switching from COUNT to COUNT(DISTINCT)? I'm sure it's slower. If it's significantly slower, we should probably keep the COUNT, and have an option in the argument handler to use COUNT(DISTINCT) instead.
- it's still not going to work in Views 3. This patch might help, but it needs testing and feedback: #1362524: add GROUP_CONCAT aggregate function; and move aggregate function helpers to a query extender?.
- it *looks like* this would work on Postgres: http://www.postgresql.org/docs/8.2/static/sql-expressions.html but what Postgres says it does and what it actually does... eh :/
Comment #20
asb commentedTo resolve this issue, coding is required -> feature request.
Comment #21
asb commentedWeird, I'm getting those bogus similaries like "3022700%" now even in Views without any relationships. D6 (Pressflow), Views 2.
The issue still exists in similarterms 6.x-2.x-dev from 2013-Oct-01.
Comment #22
hexabinaerThis is still the case in the current 8.x version. Comparing to a second project where SbT delivers quite satisfying results while in my current project we have very nested hierarchical vocabularies, I reckon this might be related to a miscalculation of (counted in) term children.
Comment #23
shelaneIf this is still an issue in the 8.x branch, create a new issue.