Basic Search Page Architecture
Problem Statement
Design the Low-Level Design (LLD) for a Basic Search Page System that allows users to enter a query, search across a dataset (such as documents, products, or profiles), and display ranked search results.
The system should handle query parsing, index lookup, ranking, and results presentation efficiently, while being modular enough to support future extensions such as filtering, sorting, or autocomplete.
🎯 Core Requirements
1. Search Query Input
2. Index Lookup
3. Ranking and Scoring
4. Result Presentation
5. Optional Features
⚙️ Functional APIs
OperationDescription
indexDocument(documentId, content)
Adds or updates a document in the searchable index.
search(query, page, size)
Executes a search query and returns paginated results.
getSuggestions(prefix)
(Optional) Returns autocomplete suggestions for a query prefix.
rebuildIndex()
Rebuilds the inverted index from raw documents.
🧱 Suggested Class Design
ClassResponsibility
Document
Represents a searchable entity (id, title, content, metadata).
Token
Represents a normalized word used for indexing.
InvertedIndex
Maintains mapping between tokens and document IDs.
Indexer
Builds and updates the inverted index.
QueryProcessor
Parses and normalizes user queries.
SearchEngine
Coordinates search, ranking, and result aggregation.
Ranker
Scores and ranks retrieved documents.
Result
Represents a single search result (title, snippet, score).
SearchController
Entry point for search requests (API layer).
🧩 Example Entities
Document
1
2documentId: D101
3title: "Wireless Noise Cancelling Headphones"
4content: "Experience high-quality sound with Bluetooth 5.0."
5metadata: { category: "Electronics", price: 2999 }Inverted Index
1
2{
3 "wireless": [D101, D102],
4 "headphones": [D101],
5 "bluetooth": [D101, D103]
6}Search Query
1
2query: "Bluetooth headphones"
3tokens: ["bluetooth", "headphones"]Result
1
2{
3 documentId: "D101",
4 title: "Wireless Noise Cancelling Headphones",
5 snippet: "...high-quality sound with Bluetooth 5.0...",
6 score: 0.89
7}🧠 Design Considerations
Index Efficiency:
Ranking:
Scalability:
Extensibility:
🔄 Example Flow
1
2indexDocument(D101, "Wireless Noise Cancelling Headphones with Bluetooth 5.0")
3→ Tokens extracted → InvertedIndex updated1
2search("Bluetooth headphones")
3→ QueryProcessor tokenizes: ["bluetooth", "headphones"]
4→ InvertedIndex lookup → [D101, D103]
5→ Ranker computes scores
6→ SearchEngine returns sorted results1
2[
3 { title: "Wireless Noise Cancelling Headphones", score: 0.89 },
4 { title: "Bluetooth Earbuds", score: 0.72 }
5]🧱 Sample Class Diagram (Conceptual)
1
2+-------------------+
3| Document |
4+-------------------+
5| id |
6| title |
7| content |
8+-------------------+
9
10+-------------------+
11| InvertedIndex |
12+-------------------+
13| +addToken(token, docId) |
14| +getDocuments(token) |
15+-------------------+
16
17+-------------------+
18| QueryProcessor |
19+-------------------+
20| +tokenize(query) |
21| +normalize(query) |
22+-------------------+
23
24+-------------------+
25| SearchEngine |
26+-------------------+
27| +search(query) |
28| +rankResults() |
29+-------------------+
30
31+-------------------+
32| Ranker |
33+-------------------+
34| +computeScore() |
35+-------------------+🚀 Possible Extensions
✅ Goal:
Design an object-oriented, modular Basic Search Page architecture that supports query parsing, index lookup, ranking, and result presentation — with extensibility for advanced search capabilities.