AND * b. ','[comma] -> OR * c. '-'[minus] -> NOT * 4. replace arbitrary function with actual sql syntax * 5. return sql string * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function boolean_mark_atoms($string){ $result=trim($string); $result=preg_replace("/([[:space:]]{2,})/",' ',$result); /* convert normal boolean operators to shortened syntax */ $result=eregi_replace(' not ',' -',$result); $result=eregi_replace(' and ',' ',$result); $result=eregi_replace(' or ',',',$result); /* strip excessive whitespace */ $result=str_replace('( ','(',$result); $result=str_replace(' )',')',$result); $result=str_replace(', ',',',$result); $result=str_replace(' ,',',',$result); $result=str_replace('- ','-',$result); /* apply arbitrary function to all 'word' atoms */ $result=preg_replace( "/([A-Za-z0-9]{1,}[A-Za-z0-9\.\_-]{0,})/", "foo[('$0')]bar", $result); /* strip empty or erroneous atoms */ $result=str_replace("foo[('')]bar",'',$result); $result=str_replace("foo[('-')]bar",'-',$result); /* add needed space */ $result=str_replace(')foo[(',') foo[(',$result); $result=str_replace(')]bar(',')]bar (',$result); /* dispatch ' ' to ' AND ' */ $result=str_replace(' ',' AND ',$result); /* dispatch ',' to ' OR ' */ $result=str_replace(',',' OR ',$result); /* dispatch '-' to ' NOT ' */ $result=str_replace(' -',' NOT ',$result); return $result; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * :: boolean_sql_where($string,$match) :: * function used to transform identified atoms into mysql * parseable boolean fulltext sql string; allows for * nesting by letting the mysql boolean parser evaluate * grouped statements * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function boolean_sql_where($string,$match){ $result = boolean_mark_atoms($string); /* dispatch 'foo[(#)]bar to actual sql involving (#) */ $result=preg_replace( "/foo\[\(\'([^\)]{4,})\'\)\]bar/", " match ($match) against ('$1')>0 ", $result); $result=preg_replace( "/foo\[\(\'([^\)]{1,3})\'\)\]bar/e", " '('.boolean_sql_where_short(\"$1\",\"$match\").')' ", $result); return $result; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * :: boolean_sql_where_short($string,$match) :: * parses short words <4 chars into proper SQL: special adaptive * case to force return of records without using fulltext index * keep in mind that allowing this functionality may have serious * performance issues, especially with large datasets * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function boolean_sql_where_short($string,$match){ $match_a = explode(',',$match); for($ith=0;$ith=4){ $stringsum_long .= " $result[$cth] "; }else{ $stringsum_a[] = ' '.boolean_sql_select_short($result[$cth],$match).' '; } } if(strlen($stringsum_long)>0){ $stringsum_a[] = " match ($match) against ('$stringsum_long') "; } $stringsum .= implode("+",$stringsum_a); return $stringsum; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * :: boolean_sql_select_short($string,$match) :: * parses short words <4 chars into proper SQL: special adaptive * case to force 'scoring' of records without using fulltext index * keep in mind that allowing this functionality may have serious * performance issues, especially with large datasets * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function boolean_sql_select_short($string,$match){ $match_a = explode(',',$match); $score_unit_weight = .2; for($ith=0;$ith