Suggest Tags: Tags consisting of multiple words
Posted: 15 December 2007 04:58 AM   [ Ignore ]
Jr. Member
RankRank
Total Posts:  49
Joined  2007-01-16

It seems, that the “Suggest Tags” function is not able to handle Tags consisting of multiple words:

“conseil federal”
“widmer-schlumpf”

Is that correct? Is there perhaps a workaround?

Thank you
MISC

Profile
 
 
Posted: 29 December 2007 11:18 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

Misc,

Thank you for noting this, it is definately a bug smile

 Signature 
Profile
 
 
Posted: 01 February 2008 02:20 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  6
Joined  2007-12-11

Hello, I just ran into this (since almost all my tags are 2-3 words).

Is there any current workaround?  I’m dying to be able to use the suggest feature.

Profile
 
 
Posted: 01 February 2008 03:17 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

VodkaFish,

I apologize completely…. the only thing I can tell you is that this bug should be fixed in the near future smile

I feel really bad because I should have remembered this when you were asking about the Module :(

 Signature 
Profile
 
 
Posted: 20 February 2008 12:01 PM   [ Ignore ]   [ # 4 ]
Jr. Member
RankRank
Total Posts:  52
Joined  2007-04-30

Woops, didn’t see this post, and I’m in the same boat.  Almost all of my tags are more than one word.

Any chance of a quick patch or fix to get this working?

Tx!

Profile
 
 
Posted: 21 February 2008 08:42 AM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

Hi guys,

This fix should happen within the next couple weeks… I apologize for the inconvenience smile

Thanks for your patience!

 Signature 
Profile
 
 
Posted: 21 February 2008 08:58 AM   [ Ignore ]   [ # 6 ]
Jr. Member
RankRank
Total Posts:  52
Joined  2007-04-30

Understood (and I see that the docs now say 2.1.0!)  wink

But I’m launching this feature on my client’s site this week, and was hoping someone (Solspace or Community) could help me out with a quick fix. 

With my extremely limited PHP/Mysql understanding,  I see what the issue is but not quite sure how to resolve it myself.

In mcp.tag.php,  the suggest function grabs the contents of the entry text, and creates an array of words.  The words are then used in the mysql query as follows:

...
AND 
tag_name IN ('".implode( "','", $DB->escape_str( $arr ) )."')
... 


So if my body text is “Hey welcome to my site!”,  the generated code is:

AND tag_name IN ('hey','welcome','to','my','site'

So it won’t find tags with the tag name “my site”  for example.  I think that all I need here is a way to use a mysql “LIKE”  operator instead of “IN”,  so that I can query the tag names using a wildcard:

AND tag_name LIKE ('hey%','welcome%','to%','my%','site%'

which would return the “my site” tag ...but I don’t think that’s the right syntax for the LIKE operator, and can’t find any documentation on using LIKE with multiple values.  I came VERY close, using the hackish:

AND tag_name LIKE '".implode( "' OR tag_name LIKE '%", $DB->escape_str( $arr ) )."' 

which did return multi-word tags,  but also returned all of the other tags for this weblog…  So close…. Any chance anyone could suggest a fix? Possible bounty for a solution.

Tx!

Profile
 
 
Posted: 21 February 2008 09:05 AM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

Haha, if we had the fix for it, we’d fix it grin

I’ll shoot this over to a developer, and perhaps we can get this solved sooner smile

And yes, the much anticipated Tag 2.1 is just clinging onto one last… err… second last… very small bug… then it’s out.
It will include a dirty monster of a list of bug fixes and new features! grin raspberry

(all except this issue unfortunately - currently - although I’m pushing hard for it) wink

 Signature 
Profile
 
 
Posted: 21 February 2008 10:04 AM   [ Ignore ]   [ # 8 ]
Jr. Member
RankRank
Total Posts:  52
Joined  2007-04-30

LOL! Tx.

Profile
 
 
Posted: 21 February 2008 12:16 PM   [ Ignore ]   [ # 9 ]
Administrator
Avatar
RankRankRank
Total Posts:  1000
Joined  2004-03-30

Yep. Pie Man is pushing hard for it indeed. That’s his job.

What you guys need to know is just how complicated this request actually is.

So we want “Hey welcome to my site” to match tags on, well, exactly what you want it to match on, which varies from user to user. Remember, the sentence you use as an example is just an illustration of what most people do. Most people have many paragraphs in the various custom weblog fields. Every word of every paragraph of every field is currently checked as a tag match. It’s hard to code, but not as hard as trying to find phrases as tags. It’s an exponential test. First you check for matches on every word. Then you would have to check for matches on every word pair, then matches on every trio, and maybe stop at four words. By now the system is not fast and fun AJAXy anymore. It’s slow like a Windows app.

We could have coded this in the other direction and gotten a list of all tags and searched the text to find where those tags occurred. That would be fine and it would catch phrases and such, but what happens when the list of tags is 20,000 which is not an uncommon usage of the Tag module these days. Then, again, performance is hosed.

So no, very sorry, but this feature request can’t be folded in right now. Not until I get smarter by several factors.

ira24, as to your question about the way you re-wrote the query, it’s fine except that it makes the matching algorithm several times LESS sensitive. You would get far too many matches that way since you use the % wildcard so liberally. It’s an interesting thought, but one that would not produce the results we want.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 21 February 2008 12:31 PM   [ Ignore ]   [ # 10 ]
Jr. Member
RankRank
Total Posts:  52
Joined  2007-04-30

Tx for the explanation, I really appreciate it and understand your concerns.

In fact,  because I know that the number of tags will be very limited on our site, I ended taking exactly one of the approaches you mentioned.

I reversed the logic, and now have the suggest function:

1) Grab the Post string, explode it to an array using “||”,  then implode it back to a string using ” ” (a space)
2) Query the tag_tags table for all tag names (we only have ~30)
3) Loop through the tag name row results and if the name is an exact match for some text in the Post string, show the Tag in the list

I hear you though,  I could see how this would be a little much if you had a few hundred tags, but for me, it’s working very well.

I could post or send the code if you think it may be useful to someone else.

Cheers,

Ira

Profile
 
 
Posted: 21 February 2008 12:42 PM   [ Ignore ]   [ # 11 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

Sure, that’d be great Ira! smile

 Signature 
Profile
 
 
Posted: 21 February 2008 12:48 PM   [ Ignore ]   [ # 12 ]
Jr. Member
RankRank
Total Posts:  52
Joined  2007-04-30

Again,  I can’t guarantee that this is the best approach but it certainly works well for my needs:

/** ----------------------------------------
 /** AJAX tag suggest
 /** ----------------------------------------*/

 
function tag_suggest()
 
{
  
global $DB$IN$LANG$PREFS$REGX;
  
  
$LANG->fetch_language_file('tag');
  
  
/** ----------------------------------------
  /** Clean str
  /** ----------------------------------------*/
  
  
$str = ( $IN->GBL('str''POST') === FALSE ) ? ''$this->_clean_str$IN->GBL('str''POST') );
  
  
/** ----------------------------------------
  /** Create array (and then blow the bastard up again. haha...)
  /** ----------------------------------------*/
  
  
$arr   explode"||"$str );
  
$arr  implode(" "$arr);
  
  
  
/** ----------------------------------------
  /** Handle existing
  /** ----------------------------------------*/
  
  
$existing = array();
  
  if ( 
$IN->GBL('existing') !== FALSE )
  
{
   $existing 
explode"||"$REGX->xss_clean$IN->GBL('existing''POST') ) );
  
}
  
  
/** ----------------------------------------
  /** Query DB / Get all available tag names except those already in use
  /** ----------------------------------------*/
  
  
$query $DB->query"SELECT tag_id AS id, tag_name AS name
  FROM exp_tag_tags
  WHERE site_id = '"
.$DB->escape_str($PREFS->ini('site_id'))."'
  AND tag_name NOT IN ('"
.implode"','"$DB->escape_str$existing ) )."')
  ORDER BY total_entries DESC LIMIT 50" 
);
  
  
/** ----------------------------------------
  /** Assemble string / for each tag name, check it against the post string, and if matches, use that tag name
  /** ----------------------------------------*/
  
$return "<ul>";
  
  if ( 
$query->num_rows == )
  
{
   $return 
.= '<span class="message">'.$LANG->line('no_matching_tags').'</span>';
  
}
  
else
  
{
   $count 
0;
   
   foreach ( 
$query->result as $row )
   
{
    
if(stristr($arr$row['name'])) 
     $count
++; 
     
$return .= '<li><a id="t'.$row['id'].'" href="#">'.$row['name'].'</a></li>';
    
}
   }
   
if ($count 1{
    $return 
.= '<span class="message">'.$LANG->line('no_matching_tags').'</span>';
   
}
  }
  
  $return 
.= "</ul>";
  
  echo 
$return;    
  
  exit;
 
}
 
 
/** End AJAX suggest */ 


Cheers.

Profile
 
 
Posted: 17 October 2008 10:18 AM   [ Ignore ]   [ # 13 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8290
Joined  2006-10-18

Thanks for the wait guys…

This is now fixed with the new version of Tag 2.5 smile
http://www.solspace.com/forums/viewthread/661/

 Signature 
Profile