|
| 1 | +# ParadeDB Movie Search Sample App |
| 2 | + |
| 3 | +A CDK application demonstrating ParadeDB's full-text search capabilities with LocalStack. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This sample app deploys a serverless movie search application using: |
| 8 | + |
| 9 | +- **AWS Lambda** - Handles search and data operations |
| 10 | +- **Amazon API Gateway** - REST API endpoints |
| 11 | +- **Amazon S3** - Stores movie dataset |
| 12 | +- **ParadeDB** - Full-text search engine (runs as LocalStack extension) |
| 13 | + |
| 14 | +### Features Demonstrated |
| 15 | + |
| 16 | +| Feature | Description | |
| 17 | +|---------|-------------| |
| 18 | +| **BM25 Ranking** | Industry-standard relevance scoring | |
| 19 | +| **Fuzzy Matching** | Handles typos (e.g., "Godfater" finds "Godfather") | |
| 20 | +| **Highlighting** | Returns matched text with highlighted terms | |
| 21 | + |
| 22 | +### API Endpoints |
| 23 | + |
| 24 | +| Method | Endpoint | Description | |
| 25 | +|--------|----------|-------------| |
| 26 | +| GET | `/search?q=<query>` | Search movies with BM25 ranking | |
| 27 | +| GET | `/movies/{id}` | Get movie details by ID | |
| 28 | +| POST | `/admin/init` | Initialize database schema | |
| 29 | +| POST | `/admin/seed` | Load movie data from S3 | |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +- [LocalStack](https://localstack.cloud/) installed and running |
| 34 | +- [Node.js](https://nodejs.org/) 18+ installed |
| 35 | +- [AWS CDK Local](https://github.com/localstack/aws-cdk-local) (`npm install -g aws-cdk-local`) |
| 36 | +- [AWS CLI](https://aws.amazon.com/cli/) configured |
| 37 | +- ParadeDB extension installed in LocalStack |
| 38 | + |
| 39 | +## Setup |
| 40 | + |
| 41 | +### 1. Start LocalStack with ParadeDB Extension |
| 42 | + |
| 43 | +```bash |
| 44 | +# Install the ParadeDB extension |
| 45 | +localstack extensions install localstack-extension-paradedb |
| 46 | + |
| 47 | +# Start LocalStack |
| 48 | +localstack start |
| 49 | +``` |
| 50 | + |
| 51 | +### 2. Install Dependencies |
| 52 | + |
| 53 | +```bash |
| 54 | +cd paradedb/sample-movie-search |
| 55 | +make install |
| 56 | +``` |
| 57 | + |
| 58 | +Or manually: |
| 59 | + |
| 60 | +```bash |
| 61 | +npm install |
| 62 | +cd lambda && npm install |
| 63 | +``` |
| 64 | + |
| 65 | +### 3. Deploy the Stack |
| 66 | + |
| 67 | +```bash |
| 68 | +make deploy |
| 69 | +``` |
| 70 | + |
| 71 | +Or manually: |
| 72 | + |
| 73 | +```bash |
| 74 | +cdklocal bootstrap |
| 75 | +cdklocal deploy |
| 76 | +``` |
| 77 | + |
| 78 | +After deployment, you'll see output similar to: |
| 79 | + |
| 80 | +``` |
| 81 | +Outputs: |
| 82 | +MovieSearchStack.ApiEndpoint = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/ |
| 83 | +MovieSearchStack.DataBucketName = movie-search-data |
| 84 | +MovieSearchStack.InitEndpoint = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/admin/init |
| 85 | +MovieSearchStack.MovieSearchApiEndpointB25066EC = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/ |
| 86 | +MovieSearchStack.MoviesEndpoint = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/movies/{id} |
| 87 | +MovieSearchStack.SearchEndpoint = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/search |
| 88 | +MovieSearchStack.SeedEndpoint = https://movie-search-api.execute-api.localhost.localstack.cloud:4566/dev/admin/seed |
| 89 | +``` |
| 90 | + |
| 91 | +### 4. Initialize Database |
| 92 | + |
| 93 | +Create the movies table and BM25 search index: |
| 94 | + |
| 95 | +```bash |
| 96 | +make init |
| 97 | +``` |
| 98 | + |
| 99 | +### 5. Seed Data |
| 100 | + |
| 101 | +Load movie data from S3 into ParadeDB: |
| 102 | + |
| 103 | +```bash |
| 104 | +make seed |
| 105 | +``` |
| 106 | + |
| 107 | +## Usage |
| 108 | + |
| 109 | +### Search Movies |
| 110 | + |
| 111 | +```bash |
| 112 | +# Basic search |
| 113 | +curl "https://<api-id>.execute-api.localhost.localstack.cloud:4566/dev/search?q=redemption" |
| 114 | + |
| 115 | +# With pagination |
| 116 | +curl "https://<api-id>.execute-api.localhost.localstack.cloud:4566/dev/search?q=dark%20knight&limit=5&offset=0" |
| 117 | + |
| 118 | +# Fuzzy search (handles typos) |
| 119 | +curl "https://<api-id>.execute-api.localhost.localstack.cloud:4566/dev/search?q=godfater" |
| 120 | +``` |
| 121 | + |
| 122 | +### Get Movie Details |
| 123 | + |
| 124 | +```bash |
| 125 | +curl "https://<api-id>.execute-api.localhost.localstack.cloud:4566/dev/movies/tt0111161" |
| 126 | +``` |
| 127 | + |
| 128 | +### Example Response |
| 129 | + |
| 130 | +```json |
| 131 | +{ |
| 132 | + "success": true, |
| 133 | + "data": { |
| 134 | + "results": [ |
| 135 | + { |
| 136 | + "id": "tt0111161", |
| 137 | + "title": "The Shawshank Redemption", |
| 138 | + "year": 1994, |
| 139 | + "genres": ["Drama"], |
| 140 | + "rating": 9.3, |
| 141 | + "directors": ["Frank Darabont"], |
| 142 | + "actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton"], |
| 143 | + "highlight": "...finding solace and eventual <mark>redemption</mark> through acts of common decency." |
| 144 | + } |
| 145 | + ], |
| 146 | + "total": 1, |
| 147 | + "limit": 10, |
| 148 | + "offset": 0 |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## Web UI |
| 154 | + |
| 155 | +A minimal web UI is included in the `web/` directory. To use it: |
| 156 | + |
| 157 | +1. Open `web/index.html` in a browser |
| 158 | +2. Set the API URL by opening the browser console and running: |
| 159 | + |
| 160 | +```javascript |
| 161 | +setApiUrl('https://<api-id>.execute-api.localhost.localstack.cloud:4566/dev') |
| 162 | +``` |
| 163 | + |
| 164 | +3. Start searching! |
| 165 | + |
| 166 | +## How It Works |
| 167 | + |
| 168 | +1. **Deployment**: CDK creates Lambda functions, API Gateway, and S3 bucket with movie data |
| 169 | + |
| 170 | +2. **Initialization**: The init Lambda creates the movies table and ParadeDB BM25 index: |
| 171 | + ```sql |
| 172 | + CALL paradedb.create_bm25( |
| 173 | + index_name => 'movies_search_idx', |
| 174 | + table_name => 'movies', |
| 175 | + key_field => 'id', |
| 176 | + text_fields => paradedb.field('title') || paradedb.field('plot') |
| 177 | + ); |
| 178 | + ``` |
| 179 | + |
| 180 | +3. **Data Loading**: The seed Lambda reads `movies.json` from S3 and inserts into ParadeDB |
| 181 | + |
| 182 | +4. **Search**: Queries use ParadeDB's BM25 search with fuzzy matching: |
| 183 | + ```sql |
| 184 | + SELECT *, paradedb.snippet(plot) as highlight |
| 185 | + FROM movies |
| 186 | + WHERE id @@@ paradedb.parse('title:query~1 OR plot:query~1') |
| 187 | + ORDER BY paradedb.score(id) DESC |
| 188 | + ``` |
| 189 | + |
| 190 | +## References |
| 191 | + |
| 192 | +- [ParadeDB Documentation](https://docs.paradedb.com/) |
| 193 | +- [LocalStack Extensions](https://docs.localstack.cloud/aws/tooling/extensions/) |
| 194 | +- [AWS CDK Local](https://github.com/localstack/aws-cdk-local) |
0 commit comments