[dev] need help to understand content tagger getTags by tag-id.
Michael J Rubinsky
mrubinsk at horde.org
Tue Aug 16 19:49:57 UTC 2011
Quoting roman stachura <roman at stachura.ch>:
> Hi horde devs.
>
>
> I was working through the Content_Tagger class.
>
> The class is nicely structured. Well done.
>
> http://git.horde.org/co.php/content/lib/Tagger.php?rt=horde-git&ws=1&r=2644a8bcaadeff77e52a5dfcc80c827b50167e79
>
> I have a question about the function
> public function getTags($args){...}
>
> line 280 :
>
>
> } elseif (isset($args['tagId'])) {
>
> $radius = isset($args['limit']) ? (int)$args['limit'] :
> $this->_defaultRadius;
>
> unset($args['limit'];
>
> $inner = $this->_db->addLimitOffset('
> SELECT object_id
> FROM ' . $this->_t('tagged') . '
> WHERE tag_id = ' . (int)$args['tagId'],
> array('limit' => $radius));
>
> $sql = $this->_db->addLimitOffset('
> SELECT DISTINCT tagged2.tag_id AS tag_id, tag_name
> FROM (' . $inner . ') tagged1
> INNER JOIN ' . $this->_t('tagged') . ' tagged2 ON
> tagged1.object_id = tagged2.object_id
> INNER JOIN ' . $this->_t('tags') . ' t ON tagged2.tag_id = t.tag_id',
> array('limit' => $args['limit']));
> } else {...
>
> What is going on here "...FROM ($inner)...?
> can someone post it in plain sql?
I don't have the code in front of me at the moment, so going from
memory here. First, to answer your question:
"FROM ($inner) tagged1" is a sql subquery with a table alias. It
allows the subquery to act as a table with a 'object_id' column. So,
e.g., later in the query we join on "tagged1.object_id =
tagged2.object_id" the tagged1 table is actually the subquery results
presented as a table.
If I'm reading the code correctly, the idea of this code is to return
tags that are present on objects where those objects are also tagged
with $args['tagId']. The radius determines the max number of other
objects to look at. For example: I have an object tagged with 'foo'
and 'bar', and another object tagged with 'foo'. If I run this query
with the tag_id for 'foo', it will return 'bar'. At least that's the
idea ;)
That being said, it looks like something might be wrong here, since
the limit value is unset() before it's used in the final query, might
be causing some WARNING to be rasied due to non-existant key.
Are you having issues with this method? I still need to fill in some
areas of the unit tests, so any information on failing behavior would
be helpful.
--
mike
The Horde Project (www.horde.org)
mrubinsk at horde.org
More information about the dev
mailing list