Want to use 2 or 3 character tags with the sNews CMS tags mod? Now you can.
filed under: sNews CMS / Hacks & Mods
OK, I hear you, the standard 4 character limit for the MySQL full-text search sucks for the tags, and you don't own the server you're on, so you can't recompile MySQL.
When running an article search, it's not a problem, you don't want people pounding your DB searching for microwords, and MySQL's full-text speed simply can't be touched so it works fine there, but it's a pain when it comes to the tags mod.
This is a problem for myself as well, as I like to use acronyms for tags, such as IE and CSS. Therefore, I have written an alternate tagsearch function. As it uses MySQL's REGEXP operator, it's more resource greedy, but unless you have 10,000 articles/pages, it shouldn't cause problems. However, if you don't want to use tags under four characters, I recommend sticking with the existing full-text tagsearch.
This is a simple drop in replacement, just BACK-UP your snews.php, first rename the existing tagsearch function to tagsearch_orig (or delete it, but I would save it to change over later if needed/desired), now copy the new tagsearch function into the bottom of your snews.php file, just before the closing php tag;
//TAGS ENGINE
function tagsearch($tags_query,$limit = 100,$min_chars = 2) {
$tags_query = clean(cleanXSS($tags_query));
echo '<h2>'.l(tag_results).'</h2>';
if (strlen($tags_query) < $min_chars) {
echo '<div><p>Tags must be at least '.$min_chars.' characters!</p>';
} else {
$tags_query = trim($tags_query);
$now = date("Y-m-d H:i:s",time());
$query = 'SELECT a.id,a.title,a.seftitle AS asef,a.date AS date,
c.name AS name,c.seftitle AS csef,
x.name AS xname,x.seftitle AS xsef
FROM '._PRE.'articles'.' AS a
LEFT OUTER JOIN '._PRE.'categories'.' as c
ON category = c.id AND c.published =\'YES\'
LEFT OUTER JOIN '._PRE.'categories'.' as x
ON c.subcat = x.id AND x.published =\'YES\'
WHERE (a.keywords_meta LIKE \'%'.$tags_query.'%\' AND a.keywords_meta REGEXP \'[[:<:]]'.$tags_query.'[[:>:]]\') AND position != 2
AND a.published = 1
AND date <= \''.$now.'\'';
if(!_ADMIN){
$query = $query.'AND a.visible = \'YES\'';
}
$query = $query.' ORDER BY date DESC LIMIT '.$limit;
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if (!$numrows) {
echo '<div><p>'.l('noresults').'
<strong>'.stripslashes($tags_query).'</strong>.</p>';
} else {
echo '<div id="tag_results"><p><strong>'.$numrows.'</strong> '.l('tagresultsfound').' <strong>'.
stripslashes($tags_query).'</strong>.</p>';
while ($r = mysql_fetch_array($result)) {
$date = date(s('date_format'), strtotime($r['date']));
if ($r['name']) { $name = ' in '.$r['name']; } else { $name = "";}
if (isset($r['xsef'])) $link = $r['xsef'].'/'.$r['csef'].'/';
else $link = isset($r['csef']) ? $r['csef'].'/' : '';
echo '<p><a href="'._SITE.$link.$r['asef'].'/">'.$r['title'].'</a><br /><span class="tag_sub">added on '.$date.$name.'</span></p>';
}
}
}
echo '</div>';
}
Make sure you set the $min_chars variable to whatever minimum you like. Now upload your snews.php file and you should be in business. Leave the meta_keyword full-text index alone, as I'm working on an advanced search that will match against it, to be released at a future date :)
I am updating the tags mod to include this option as well.
Comments
No comments posted yet, why not be the first?
Categories
Recent Entries
Recent Comments
- Redbeard (I managed to get Vampire: The Masquerade - Bloodlines ...)
- Tina (Installed this today and working like a charm :) Thanks!)
- Tina (Thanks for this great mod :) Working on my site for quite a ...)
- konga (Hi Matt, if you plan to update it, please have a look into ...)
- David (Yo Matt, I have a problem, when I use this mod. ...)
- Dave (Have a Toshiba NB305. Win7 starter would not do screen ...)
- Daichisan (Howdy Matt, I dont really get it, whats ...)
- Matt (Mine is just customized further, that's all :) It just spits ...)
- Matt (David, Do you own or admin the server? Do you have exec ...)
Popular Entries
- Compact archives for sNews 1.7 (5/5)
- Light-weight related articles mod for sNews 1.7 (4.78/5)
- SEF / SEO search for your sNews website (4.75/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.67/5)
- Gravatar mod for sNews 1.7 (4.67/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
- Command & Conquer Generals, and the Zero Hour expansion on the Acer Aspire One netbook (4.6/5)
- Related Articles mod for sNews CMS, public beta release (4.6/5)