Search Engine (Python, MongoDB)

A Python search project combining an inverted index, TF-IDF, and link analysis.

Concept illustration of documents passing through posting lists to search results
Concept illustration of document indexing and ranked retrieval.

Build the route from a query to a ranked page

I worked with a teammate on a search engine for the UCI ICS corpus, using Python, MongoDB, NLTK, BeautifulSoup, and Flask. We built an inverted index, precomputed ranking information, and exposed results through a command-line interface and a JSON API.

I focused on pipeline orchestration, HTML-aware preprocessing, bigram indexing, TF-IDF integration, and the retrieval logic that combines postings into ranked results. I also helped connect PageRank scores to the ranking formula and structure the MongoDB collections.


Preserve signals from the document

Preprocessing extracts text from HTML, normalizes and lemmatizes tokens, and removes stop words. We give different weights to locations such as titles, headings, and emphasized text, rather than treating every occurrence identically.

The index includes single tokens and bigrams. Query preprocessing uses the same approach so a query can be matched against the representation created during indexing.


We extracted outbound links to construct a graph and computed PageRank values. The implemented per-token score combines term frequency, inverse document frequency, tag weighting, and the document’s PageRank:

score(term, document) = TF × IDF × tag weight × PageRank

Our ranking design combines textual relevance with link importance. That choice has a specific tradeoff: multiplying by PageRank can favor well-linked pages even when a less-connected page is more directly relevant.


Keep indexing separate from retrieval

MongoDB stores document metadata and snippets separately from token postings. The indexing pipeline uses a process pool for document work; scoring and retrieval also use parallel tasks. At query time, the search layer retrieves per-token postings and merges their scores before formatting the results.

The Flask endpoint accepts a query and returns results with timing and result-count information. An interactive CLI provides another way to inspect the same retrieval behavior.


Running the course project

python src/main.py

The project expects MongoDB and its Python dependencies, along with the course corpus. Its modules separate preprocessing, indexing, link ranking, score calculation, storage, and search.


What I learned

Search quality depends on many choices before the final sort. Token normalization changes what can match; HTML weights change which occurrences matter; link scores change which pages are favored. Building the pipeline taught me to make ranking decisions inspectable and to use an evaluation set when comparing retrieval quality.