<?php
    
///////////////////////////////
    // CODEgrunt - total geek trash, coder for hire
    // http://codegrunt.com
    //
    // This is an example code excerpt showing one way to work around MySQL's fulltext searching limits, specifically stop words and
    // default minimum 4 letter word length.
    // The code below would normally be embedded in a MySQL class or equivalent.

    
define('_search_suffix','ggzzxxyypp'); // search suffix should be something unlikely to show up in normal data

    // pad words to length of search suffix
    
function gen_search_word($w)
    {
        return (
$w.substr(_search_suffix,0,strlen(_search_suffix)-strlen($w)));
    }

    function 
prepare_for_fulltext_search($text='')
    {
        
$words=explode(' ',preg_replace('/[\s]+/',' ',strtolower(preg_replace('/[^-_a-zA-Z0-9]/',' ',$text.' '.strip_tags($text)))));
        if(
count($words)>0)
        {
            
$stop_words_unwanted=array('a','the','an','on','of');
            
$stop_words_wanted=array(
'able','about','above','according','accordingly','across','actually','after','afterwards','again','against','all','allow','allows','almost','alone','along','already','also','although','always','am','among','amongst','an','and','another','any','anybody','anyhow','anyone','anything','anyway','anyways','anywhere','apart','appear','appreciate','appropriate','are','around','as','aside','ask','asking','associated','at','available','away','awfully','be','became','because','become','becomes','becoming','been','before','beforehand','behind','being','believe','below','beside','besides','best','better','between','beyond','both','brief','but','by','came','can','cannot','cant','cause','causes','certain','certainly','changes','clearly','co','com','come','comes','concerning','consequently','consider','considering','contain','containing','contains','corresponding','could','course','currently','definitely','described','despite','did','different','do','does','doing','done','down','downwards','during','each','edu','eg','eight','either','else','elsewhere','enough','entirely','especially','et','etc','even','ever','every','everybody','everyone','everything','everywhere','ex','exactly','example','except','far','few','fifth','first','five','followed','following','follows','for','former','formerly','forth','four','from','further','furthermore','get','gets','getting','given','gives','go','goes','going','gone','got','gotten','greetings','had','happens','hardly','has','have','having','he','hello','help','hence','her','here','hereafter','hereby','herein','hereupon','hers','herself','hi','him','himself','his','hither','hopefully','how','howbeit','however','ie','if','ignored','immediate','in','inasmuch','inc','indeed','indicate','indicated','indicates','inner','insofar','instead','into','inward','is','it','its','itself','just','keep','keeps','kept','know','knows','known','last','lately','later','latter','latterly','least','less','lest','let','like','liked','likely','little','look','looking','looks','ltd','mainly','many','may','maybe','me','mean','meanwhile','merely','might','more','moreover','most','mostly','much','must','my','myself','name','namely','nd','near','nearly','necessary','need','needs','neither','never','nevertheless','new','next','nine','no','nobody','non','none','noone','nor','normally','not','nothing','novel','now','nowhere','obviously','off','often','oh','ok','okay','old','on','once','one','ones','only','onto','or','other','others','otherwise','ought','our','ours','ourselves','out','outside','over','overall','own','particular','particularly','per','perhaps','placed','please','plus','possible','presumably','probably','provides','que','quite','qv','rather','rd','re','really','reasonably','regarding','regardless','regards','relatively','respectively','right','said','same','saw','say','saying','says','second','secondly','see','seeing','seem','seemed','seeming','seems','seen','self','selves','sensible','sent','serious','seriously','seven','several','shall','she','should','since','six','so','some','somebody','somehow','someone','something','sometime','sometimes','somewhat','somewhere','soon','sorry','specified','specify','specifying','still','sub','such','sup','sure','take','taken','tell','tends','th','than','thank','thanks','thanx','that','thats','their','theirs','them','themselves','then','thence','there','thereafter','thereby','therefore','therein','theres','thereupon','these','they','think','third','this','thorough','thoroughly','those','though','three','through','throughout','thru','thus','together','too','took','toward','towards','tried','tries','truly','try','trying','twice','two','un','under','unfortunately','unless','unlikely','until','unto','up','upon','us','use','used','useful','uses','using','usually','value','various','very','via','viz','vs','want','wants','was','way','we','welcome','well','went','were','what','whatever','when','whence','whenever','where','whereafter','whereas','whereby','wherein','whereupon','wherever','whether','which','while','whither','who','whoever','whole','whom','whose','why','will','willing','wish','with','within','without','wonder','would','would','yes','yet','you','your','yours','yourself','yourselves','zero'
);
            foreach(
$words AS $k=>$w)
            {
                if(
strlen($w)<|| in_array($w,$stop_words_unwanted)) unset($words[$k]);
                else if(
strlen($w)<4$words[$k]=MySQL::gen_search_word($w);
                else if(
in_array($w,$stop_words_wanted)) $words[$k]=MySQL::gen_search_word($w);
            }
            
$words=implode(' ',$words);
        }
        return 
$words;
    }
?>