How your search method works is dependant on what you're searching. Are you searching a database? A collection of files?
If it's a database, I'm sure your database server will have searching functions inbuilt into it. mySQL has the Fulltext search functionality for things such as this. I can't comment on the other database servers though - I haven't worked in them.
If it's files, then you will need to loop across the files you want to search. You can then probably get away with using a regular expression to match the words, and then act based on what entries match the expression.