SmartSearch โ E-Commerce Product Search & Ranking Engine
A high-performance product search engine powered by a custom C++ DSA engine bridged to a Flask REST API with PostgreSQL persistence. Built for SDE portfolio demonstrations, tackling classic backend engineering challenges using custom data structures.
๐ Project Overview
SmartSearch solves three classic backend engineering challenges using custom data structures implemented in C++:
- Real-time autocomplete: Trie (O(L) per lookup)
- Top-10 best products ranking: Min-Heap (O(N log K))
- Avoid repeating expensive queries: LRU Cache - HashMap + Doubly Linked List (O(1) get/put)
- Filter products by price range: Binary Search on sorted array (O(log N))
๐๏ธ Architecture
Browser (HTML + CSS + Vanilla JS) → Flask REST API (Python) → C++ DSA Engine (engine2.dll) & PostgreSQL (SQLAlchemy)
Data flow for a search request:
- User types "nike shoe" + price ₹2000–₹10000
- Flask receives GET
/api/search?q=nike+shoe&min_price=2000&max_price=10000 - C++ Engine checks LRU Cache (HashMap lookup O(1))
- CACHE HIT: return cached result instantly
- CACHE MISS: Binary Search on price-sorted array O(log N) → substring filter on price-range slice → Min-Heap Top-10 by ranking score O(M log K) → store result in LRU Cache
- Flask fetches full product details from PostgreSQL by IDs
- Browser renders Top-10 cards + DSA Performance Panel
๐ง DSA Components Deep Dive
1. ๐ Trie โ Autocomplete
Each TrieNode stores up to 10 product IDs at every prefix. O(L) lookup where L = length of the typed prefix. Used for real-time autocomplete dropdown.
2. ๐ Min-Heap โ Top-K Ranking
Ranking Score = (Rating × 0.5) + (Popularity × 0.3) + (Relevance × 0.2) normalized to /10. Min-Heap of size K=10 keeps only the top-K candidates. Result: O(N log K) — far faster than sorting all N results.
3. โก LRU Cache โ O(1) Repeated Queries
HashMap (O(1) lookup) + Doubly Linked List (O(1) eviction) with a capacity of 100 cached queries. On every search: check HashMap → O(1) hit or miss. Cache key includes query + price range.
4. ๐ข Binary Search โ Price Range Filter
Products pre-sorted by price at engine load time. Binary search finds the slice in O(log N). Min-Heap then ranks only the M products in that slice — O(M log K). When price filter is ON: complexity drops from O(N log K) → O(M log K) where M << N.
๐ง C++ โ Python Bridge (ctypes)
The C++ engine compiles to a Windows DLL (engine2.dll). Python loads it via ctypes. Products are passed from Python → C++ as a pipe-delimited CSV string on engine startup to avoid JSON parsing overhead when loading 1000+ products into C++.
๐งช Try It Live & View Code
Click here to launch the live Platform
View the complete codebase on GitHub
๐ Connect with Me
๐ www.tauqueeralam.com
๐ฑ LinkedIn | GitHub
View the live demo below:
View Live Demo
Discussion