[dev] need help to understand content tagger getTags by tag-id.

roman stachura roman at stachura.ch
Tue Aug 16 20:51:17 UTC 2011


Am 16.08.2011 21:49, schrieb Michael J Rubinsky:
>
> 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.
Allright this one is called a "inline-View"
And the SQL looks like this :

SELECT DISTINCT tagged2.tag_id AS tag_id, tag_name
FROM (
     SELECT object_id
     FROM rampage_tagged
     WHERE tag_id = XXX
     LIMIT 0, 10
) AS tagged1
INNER JOIN rampage_tagged tagged2 ON tagged1.object_id = tagged2.object_id
INNER JOIN rampage_tags t ON tagged2.tag_id = t.tag_id
LIMIT 0, 10

>
> 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 ;)
Thanks to clarify this one.

>
> 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.
You are right.
The outer query should use the $radius var.

>
> Are you having issues with this method? 
not jet...
just getting familier with the code structure and design pattern  of 
horde 4
> I still need to fill in some areas of the unit tests, so any 
> information on failing behavior would be helpful.
I let you know if I find any more.

Regards roman
>
>






More information about the dev mailing list