List of refine tags wrong for free tagging
admincyma - September 23, 2006 - 23:15
| Project: | Refine by taxonomy |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Bèr Kessels |
| Status: | needs work |
Description
The list of returned tags is incomplete for free tagging (interconnected through nodes). The following code is correct:
# get the tag and a basic tag-node array
$query_1 = 'SELECT DISTINCT(tn0.tid), td.name, td.vid, COUNT(tn0.nid) AS nCount FROM {term_data} td INNER JOIN {term_node} tn0 ON td.tid = tn0.tid';
# add a join for each tag in the query
for ($i = 1; $i <= count($tids); $i++) {
# we want rows matching each node (all the tags of each node)
# and rows matching the tag in the query
# and rows where the tag in the basic array is not the tag of the query
$query_4 .= ' INNER JOIN {term_node} tn'. $i .' ON (tn'. $i .'.nid = tn0.nid AND tn'. $i .'.tid = '. $tids[$i - 1] .' AND tn0.tid <> '. $tids[$i - 1] . ')';
}
# compile the query and add pretty printing
$query = $query_1 . $query_4 . ' GROUP BY tn0.tid ORDER BY nCount DESC, td.name';but it is beyond my abilities to correct the module with something similar.

#1
I cannot see right away wnat is wrong and how you fixed it. Care to elaborate?
#2
Issue should be obvious from any sort of serious testing using free tagging. Say we have 3 nodes (1,2,3) tagged with (a,b), (b,c), (a,d). Filtering on a should give b and d as related tags. Module doesn't at the moment (it does for such a simple example).
The query in the module does one join with multiple where clauses. Code proposed creates multiple joins.
If you can't see this in your test environment (you needs lots of tagged nodes), I may try to find the time to figure out a problematic data set.
#3
The list of tags I get is few than existent tags.
For example:
I have one main vocab for categories like yellow pages.
Another vocab for other attributes when apply, for example, all related to restaurants are also tagged with the cooking type.
Another for locations, for example, neighbourhood or city where is located, or delivery coverage, then, more than one term of this vocab could be selected for the same node.
Then when I look at Restaurants, the other two vocabs are in blocks, for optionally refine by cooking or city, but only 7 cities are shown (I have more than this). All of the cities are tagged in the same way.
Any ideas? The code submitted above is to correct this behaviour?
Thanks in advance
#4
I spent some time looking at the query again and figured out the issue: extra tags of nodes sharing more than one tag amongst them are not reported.
Let's say we have the following list of terms-nodes (number is node, letter is term-tag):
--1a
--1b
--2a
--2b
--2c
Let's say a, b and c all belong to the same vocabulary. Let's also say the currently selected term is b, so that the current node list is (1, 2). At this stage we can all agree the related tags are (obviously) a and c.
--SELECT tn.tid
--INNER JOIN td ON td.tid = tn.tid WHERE td.vid in $delta
At this stage of the query we have all term-nodes above, all terms being in the same vocabulary $delta.
--AND tn.tid not in (current tids)
This removes 1b and 2b from the list given b is the current term. The remaining term-nodes are therefore:
--1a
--2a
--2c
--AND tn.nid in (current nids)
This empties the list of term-nodes given both 1 and 2 are in the current nodes.
However this is wrong since 'c' is a tag you can refine the query with (and get 2 as single result of the b,c tag combination (assuming AND)). 'a' is also a valid related tag even though it would not reduce the number of returned nodes.
The solution as proposed above is a query returning a number of inner joins.
Hope this helps.
#5
Thanks you for your time. Sorry, I get confused with the SQL and the inner joins consideration.
Please, take a look there:
the list with the refine by Ubicacion (Location) and Cocina (Cooking) is here:
http://www.inforo.com.ar/avisos/restaurants_bares_y_pubs/restaurantes
A view with the same data and terms:
http://www.inforo.com.ar/test/restaurantes
For example, location terms for nids 1281 (Belgrano) and 463 (La Boca) are not in the refine by Ubicacion.
But, I made one of this nodes sticky, the term appears first in the refine list and the original goes off!
I´m not an experienced programmer, but something in the looping and the order which the terms are analyzed could be bug.
I'm running refine by taxo, the current release with no patches.
#6
I need a real patch in order to understand the proposed changes and the problem at hand.
#7
I propose you try for yourself the scenario above. 2 nodes, 3 terms in the same vocabulary: I don't think it is too hard to replicate. I think this will be the best way for you to "understand the problem at hand".
#8
What about the stickness of a node? The term can appear or dissapear from the refine upon this attribute, and, of course, moving out another term from the block list.
#9
See here kaisu.org: http://plymouth.kaisu.org/ (this url is an alias for http://www.kaisu.org/taxonomy/term/988).
The links are in 'Also with tag:' block. I cannot see what is wrong.
#10
Sorry. I don´t understand so much the structure because I don´t know what is in each vocab, but, for example:
why http://plymouth.kaisu.org/taxonomy/term/988%2C1260 is not in http://www.kaisu.org/taxonomy/term/988 refine blocks? or node 1260 is not from Kaisus or Tags vocabs?
#11
In my example (now the list hace changed due to new information appeared)
The new example is:
Restaurants: http://www.inforo.com.ar/taxonomy/term/100
Refine by taxo block has 9 Locations:
http://www.inforo.com.ar/taxonomy/term/100%2C670
http://www.inforo.com.ar/taxonomy/term/100%2C671
http://www.inforo.com.ar/taxonomy/term/100%2C672
http://www.inforo.com.ar/taxonomy/term/100%2C673
http://www.inforo.com.ar/taxonomy/term/100%2C674
http://www.inforo.com.ar/taxonomy/term/100%2C655
http://www.inforo.com.ar/taxonomy/term/100%2C659
http://www.inforo.com.ar/taxonomy/term/100%2C676
http://www.inforo.com.ar/taxonomy/term/100%2C677
I don´t know why
http://www.inforo.com.ar/taxonomy/term/100%2C140
is not in the block, 140 is another location from the same vocabs and the same dpeth level as 670, 671, etc.
#12
In your example: http://www.kaisu.org/taxonomy/term/988, the first entry about "how Barnacles recognizes each other" has Kaisus:
* Marine Biology * Newcastle University * Newcastle upon Tyne * Plymouth * South West England * UK * University of Plymouth
The Also in Kaisus lists:
* Devonport Dockyard * Plymouth Barbican * sea slugs * Marine Biology * South West England * University of Plymouth * UK
What happened to * Barnacle * Newcastle University * Newcastle upon Tyne ?
Entry "Events coming up over the next year" (p2) has Kaisus: * Devon : not in the Also list
Entry "Is it a Cormorant?" has Kaisu: # Looe # South West Coast: not in the Also list.
It is possible that you have limited the size of the Also Kaisu list, but we're saying that even at a value of a 100, it fails to list ALL the possible refine tags possible.
Hope this clarifies
#13
«It is possible that you have limited the size of the Also Kaisu list,
but we're saying that even at a value of a 100, it fails to list ALL the
possible refine tags possible.»
Off course. And I was sure it is something this silly. Off course it is limited. I think that is the reason I 'don't see the problem', because afaiks it works the way it should work.
So: again: without a patch I will not consider putting time and effort in this issue. Sorry.
#14
Dear Bèr,
Don´t sorry. First of all, thank you for your time and dedication.
I´ve no patch for submission and, as I told you before, I´m not an experienced programmer. I think this module is really useful and I want it running ok with all datasets, including mine.
I'm always really commited to do the things work, no matter of the effort, then, I´m going to learn PHP and SQL in order to help if I can.
In my first approach to PHP and SQL, I traced the string $sql and $conditions just before the SELECT statement (#190), and, $conditions is really short, has only 10 $nids. Then, tomorow (now is really late here) I´ll continue tracing this string back.
Regards,
Gustavo
#15
cranking this up and assiging to myself.
#16
Don´t want to bother. Just for help if I can, I want to write a summay of the 2 problems I´ve found.
---------------
vocab A (for example, classifieds)
A1
-A11
-A12
-A13
---------------
vocab B (for example, locations)
B1
B2
...
B99
---------------
vocab C (whatever)
---------------
nid1 (A12,B1)
nid2 (A12,B2)
...
nidnn (A12,B99)
---------------
A Refine by taxo block with vocab B
1) Looking A12, not all "Bnn" are shown in block, and if you explore a nid which their "Bnn" is not in the list, and makes it sticky, this "Bnn" will appear now in the list, moving out another "Bnn" that was originally in the list. I expect all "Bnn" in the block.
2) Looking A1 (no nids in this level, the nids are only in the child category A12), in the refine by taxo block there are terms of vocab "C" (yes, "C"). I expect an empty block, because ther are no nids in this taxonomy level.
In both cases, the SQL sentence in line 190 has the only condition "NOT IN(A12)" or "NOT IN(A1)" and all the nids are returned except the condition, but not limited to nids with terms in vocab "B" which was requested for the block.
#17
Sorry, I forget something in the example that shoots problem (2),
---------------
vocab A (for example, classifieds)
A1 Restaurants Bars and Pubs
-A11 Restaurant
-A12 Bars
-A13 Pubs
A2 Cars and Vans
-A21 Cars
-A22 Vans
---------------
vocab B (for example, locations)
B1 Location1
B2 Location2
...
B99 Location99
---------------
vocab C
C1 Selling
C2 Buying
---------------
---------------
nid1 (A12,B1) a bar in location 1
nid2 (A12,B2) a bar in location 2
...
nidnn (A12,B99) a bar in location 99
nidmm (A21, C1) a car for sale
---------------
In the problem 2, looking at A1 (Restaurants bars and pubs), in the block appears a term of vocab C, for example, "selling", and there are no Restaurants for sale, only cars.
#18
Hi, I´m back.
I´ve made a snippet that reflects what I wanted. I get some pieces of code from refine by taxo and other support posts and put all together there.
May be this will reflect what I was trying to obtain:
<?php
// This snippet, when navigating through taxonomy/term1,term2...termn,
// a) always shows current terms in screen like "you are looking at term1...termn"
// b) if you have in screen a term of your selected vocabulary, also shows a link to:
// b.1) the vocabulary, if it´s the only term in url and is owned by your selected vocab,
// b.2) the taxonomy/term1,term2...termn, only excluding this term, i.e. "Show all whatever"
// c) if you don´t have in screen your vocab, also shows AND links to all the terms in your
// selected vocab for the current path (like a refine) adding to path ',term'
// d) with the "a)" condition, adds link to reset the path to only term1, term2...
// like "show all whatever1, 2.."
// Don´t implement without testing... Recomendation for testing: If you put this in a block, make it
// only visible for a restricted path
// Known bug, don't crash, sometimes may show additional terms (prior Clause C).
// This is because the selection is made with only one INNER JOIN instead of one for each term in path
// Don´t forget to change the next 5 constants and good luck
$ourvid=10; // change to vid
$resetmsg = 'Show all ';
$othermsg = 'Show other whatever'; // whatever refers to vid name
$wheremsg = 'You are looking at';
$seemsg = 'Show only';
// Clean output string
$output = '' ;
// look in args for 'taxonomy/term/xxxx' in order to determine if is something to do
if (arg(0) == 'taxonomy' &&
arg(1) == 'term' &&
preg_match('/^([0-9]+[+, ]?)+$/', arg(2))):
// Obtain current tids in path
$ourvidinpath= FALSE;
$ourselectedterm='';
$tids = $replace = $with = array();
$replace = array(",", "+");
$with = array(" ", " ");
$cleanarg = str_replace($replace, $with, arg(2));
$tids = explode(' ', $cleanarg);
// make a new path without tids in our vocab
$terms = array();
$newpath = '';
$i=0;
if (count($tids) >0 ):
foreach ($tids as $tid) {
$terms[$tid] = taxonomy_get_term($tid);
$ourselectedterm .= ' ' . $terms[$tid]->name;
if ($ourvid <> $terms[$tid]->vid):
if ($i++ > 0) $newpath .= ',';
$newpath .= $tid;
else:
$ourvidinpath= TRUE;
endif;
}
endif;
// if our vid in path, don´t show terms to refine for, show the msg to go back for other selections
$output .= $wheremsg . ' <b>' . $ourselectedterm . '</b> ';
if ($ourvidinpath):
// if only our vid in path, allow select other terms through the vocab link
if (count($tids)==1):
$output .= '<a href="/taxonomy/vocabulary/'. $ourvid. '">'. $othermsg.' </a>';
else:
$output .= '<a href="/taxonomy/term/'. $newpath. '">'. $othermsg.' </a>';
endif;
else:
// Build SQL statement, this will return all terms for vocabulary &vid for 'taxonomy/term/xxxx' taxonomy
$output .= '<p> '. $seemsg . ':</p>';
$sentence = "SELECT DISTINCT td.tid, td.name FROM term_node tn INNER JOIN term_node b ON tn.nid=b.nid INNER JOIN term_data td ON tn.tid=td.tid WHERE td.vid=" . $ourvid . " and b.tid in('" . arg(2) . "') ORDER BY td.name";
$vocabulary = db_query($sentence);
// Build output string with selected taxonomy links
while ($term = db_fetch_object($vocabulary)) {
$output .= '<a href="/taxonomy/term/'. $newpath . ',' .$term->tid. '">'. $term->name.' </a>';
}
endif;
// Add Reset filter links: If more than one taxonomy level is shown, show reset filter links
$terms = array();
if (count($tids) >1 ):
$output .= '<p>'. $resetmsg;
foreach ($tids as $tid) {
$terms[$tid] = taxonomy_get_term($tid);
$output .= '<a href="/taxonomy/term/'. $tid. '">'. $terms[$tid]->name .' </a>';
}
$output .= '</p>';
endif;
print $output;
endif;
?>
Regards,
Gustavo
#19
Can you make a patch from this? Taht way we can see what you mean in a better way.
#20
Of course, so glad to send.
Now I´m urgent with this http://drupal.org/node/100826 may be me hosting made some update, I don´t know
Thanks
Gustavo
#21
PLease read drupal.org/diffandpatch for info on how to make real patches.
#22
Thank you very much for the guidelines.
The code I´ve posted here is not a patch to apply in, i.e., an existent module. It´s a new snippet. There is nothing to compare with.
I.e. comparing this with refine by taxo module all the lines are going to be different.
So, If I don´t missunderstand something, there is no sense to make a patch. I don´t know, may be I´m wrong, please tell me.
If you with like to see how does it work, you can go to http://www.inforo.com.ar in almost every page this kind of refine apply, depending on the vocabulary, those blocks are on the right side,
i.e.
Restaurants: http://www.inforo.com.ar/taxonomy/term/100
Italian food: http://www.inforo.com.ar/taxonomy/term/186
Hotels 5*: http://www.inforo.com.ar/taxonomy/term/96
Newspapers: http://www.inforo.com.ar/taxonomy/term/727
....whatever
Sorry, those pages are in spanish, no i18 installed, but through google translate you can navigate
first 2 examples: http://translate.google.com/translate?u=http%3A%2F%2Fwww.inforo.com.ar%2... or
http://translate.google.com/translate?u=http%3A%2F%2Fwww.inforo.com.ar%2...
some translations are really funny but terms are almost clear.
Please, tell me how may I contribute, I want if I can
Regards, gustavo
#23
Hi, Any news? May I help in some way? Gustavo
#24
Gustavo, I get timeouts on your site, hecne I cannot look at the examples.
Please try to attach a normal patch. My resources and time are short, so I really need to have proper patches to review.
#25
the timeouts are due to a db restore running at this moment. My hosting provider made a mess in the collation upgrading the mysql version. I´m realy sorry for this delays. In few hours it´s going to restablished.
About the patch really, as I told you in #22, I don´t understand what I have to do. As per of my understand of a patch, is a concatenation of additions and deletions to repare a source file. I have not modified the refine by taxo module, then, there is no patch to generate. I´ve made a similar snippet that has less funcionality but fits my needs, and I guess, could be useful for another else. This snippet doesn´t contemplate "OR"'s nor Tags clouds, and it´s not implemented as a module as RbTaxo is.
Please, let me know how I can contribute. I'll be very glad to do so.
#26
I think this bug is related to http://drupal.org/node/120271