Custom Full-text Search Against Stopwords And Special Characters Using PHP And Mysql
I'm not sure if this is the best way.
To clean I pass the data through this class, all it does is strip out any special characters, and a list of stop words that I don't want to include in searches:
To clean I pass the data through this class, all it does is strip out any special characters, and a list of stop words that I don't want to include in searches:
<?php class Cleaner { var $stopwords = array(" find ", " about ", " me ", " ever ", " each ", " update ", " delete ", " add ", " insert ", " where ", " i ", " a ", " my ");//you need to extend this big time. var $symbols = array('/','\\','\'','"',',','.','<','>','?',';',':','[',']','{','}','|','=','+', '-','_',')','(','*','&','^','%','$','#','@','!','~','`'); function parseString($string) { $string = ' '.$string.' '; $string = $this->removeStopwords($string); $string = $this->removeSymbols($string); return $string; } function removeStopwords($string) { for ($i = 0; $i < sizeof($this->stopwords); $i++) { $string = str_replace($this->stopwords[$i],' ',$string); } return trim($string); } function removeSymbols($string) { for ($i = 0; $i < sizeof($this->symbols); $i++) { $string = str_replace($this->symbols[$i],' ',$string); } return trim($string); } }Source : http://stackoverflow.com/a/9082165
Comments
Post a Comment