How to build a textual search engine?
pre-process your documents (some of the steps may be skipped)

tokenize
remove stop words
stem or lemmatize
do normalization (e.g. U.S.A. -> USA, météo -> meteo, etc) and orthographic correction 
perform phonetic normalization (e.g. with Soundex)
find equivalence classes (using thesauri, e.g. WordNet) 

use a Vector Space model to represent documents (you may use TF, aforementioned TF-IDF or other models)
do the same with the query: preprocess and represent it in the vector space
find the most similar documents by computing the vector similarity (e.g. using the cosine similarity)


That's an outline of the Information Retrieval process 

Introduction to Information Retrieval by Christopher D. Manning, Prabhakar Raghavan and Hinrich Schütze is a very good book to get started in IR.



Or just use Apache Solr to get everything you need out of the box (or Apache Lucene, that is used by Solr, to build your own application)