Search Engine Project
A full-stack search engine application with an inverted index, TF-IDF, and cosine similarity for efficient text search. The backend is built with TypeScript and Express, using Prisma and PostgreSQL for data storage. The frontend is a React application for user interaction.
- Backend: TypeScript, Express.js, Node.js, Prisma, PostgreSQL
- Frontend: React.js
- Development Tools: nodemon, ts-node, npm, Visual Studio Code
- Containerization: Docker, Docker Compose
Search/
├── Server/ # Backend (Express, TypeScript)
│ ├── app.ts # Main server file
│ ├── prisma/ # Prisma schema and migrations
│ │ └── schema.prisma
│ ├── package.json
│ ├── nodemon.json
│ ├── tsconfig.json
│ └── .env
├── client/ # Frontend (React)
│ ├── src/
│ │ └── App.js
│ └── package.json
├── docker-compose.yml # Docker Compose configuration
└── README.md
- Node.js (v20+)
- Docker Desktop
- PostgreSQL (optional for local dev without Docker)
- Git
git clone https://github.com/your-username/search-engine.git
cd search-engine-
Ensure Docker Desktop is running.
-
Start services:
docker-compose up --build
-
Run Prisma migrations (in a new terminal):
docker-compose exec backend bash npx prisma migrate dev --name init -
Access the application:
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:5000 - PostgreSQL:
localhost:5432
- Frontend:
-
Stop services:
docker-compose down
-
Backend Setup:
cd Server npm install -
Configure Environment:
-
Create
Server/.env:DATABASE_URL=postgresql://postgres:your_password@localhost:5432/search_engine_db?schema=public -
Replace
your_passwordwith your PostgreSQL password.
-
-
Set Up PostgreSQL:
-
Create database:
psql -U postgres -c "CREATE DATABASE search_engine_db;"
-
-
Run Prisma Migrations:
npx prisma migrate dev --name init
-
Start Backend:
npm run dev
-
Frontend Setup:
cd ../client npm install npm start -
Access the application:
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:5000
- Frontend:
-
Add a Document:
-
Send a POST request to
http://localhost:5000/api/documents:{ "content": "Python is a versatile, high-level programming language..." }
-
-
Search Documents:
- Use the frontend at
http://localhost:3000or send a GET request tohttp://localhost:5000/api/search?query=python.
- Use the frontend at
-
Sample Database Dump:
-
To simulate data, apply the SQL dump (
search_engine_db_dump.sql):docker-compose exec db psql -U postgres -d search_engine_db -f /app/search_engine_db_dump.sqlOr locally:
psql -U postgres -d search_engine_db -f Server/search_engine_db_dump.sql
-
- POST /api/documents: Add a document (body:
{ "content": "text" }) - GET /api/search?query=: Search documents by query term
- Empty search results: Ensure
computeTfIdfinapp.tshandlesdf=0cases (seeServer/app.ts). - Prisma errors: Run
npx prisma generateandnpx prisma migrate dev. - Docker issues: Verify Docker Desktop is running and ports
3000,5000,5432are free.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit changes (
git commit -m "Add YourFeature"). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
MIT License