Search Optimization
See how I optimized search using Appwrite
Ria Choi

Intro
Search looks simple. A box, a button, some results.
But a good search feels fast and never breaks. That takes a few smart choices.
I built this movie app by following a tutorial on YouTube. The tutorial is from the JavaScript Mastery channel. I did not invent the project from scratch.
What I did was study how the search works and why each choice matters. This post shares what I learned.
The app uses React, Vite, and the TMDB API.

Live demo: https://ria-movie-search.vercel.app
Tutorial video: https://www.youtube.com/watch?v=dCLhUialKPQ
What the App Does
Users can search thousands of movies. Each result shows a poster, title, rating, language, and release year.
The app also tracks popular searches. That data lives in Appwrite.
Tech Stack at a Glance
| Tool | Role |
|---|---|
| React | UI and state management |
| Vite | Fast dev server and build |
| TMDB API | Movie data and posters |
| Appwrite | Cloud database for trending searches |
| ESLint | Code quality checks |
Optimization 1: A Controlled Search Input
The Search component is a controlled input. React state owns the value.
Every keystroke updates searchTerm. The parent component then decides when to run the search.
Why this helps:
- One source of truth for the input
- Easy to reset, trim, or validate
- Clean separation between UI and search logic

Optimization 2: Safe Rendering With Fallbacks
API data is never perfect. Some movies have no poster. Some have no rating. Some have no release date.
The MovieCard component handles all of this.
| Missing Data | What the App Does |
|---|---|
| Poster | Shows a local fallback image |
| Rating | Shows a safe default instead of crashing |
| Release date | Shows a placeholder instead of a blank |
The rating is also formatted to one decimal place. That keeps cards clean and consistent.

Optimization 3: Smarter Poster Loading
Posters come from the TMDB image CDN.
If poster_path exists, the app builds this URL:
The w500 size is a good balance. It looks sharp without loading huge files.
If there is no path, the app uses a local image instead. No broken image icons.
Optimization 4: Tracking Trending Searches
This part was my favorite. Every search teaches the app what people want.
The updateSearchCount function stores search popularity in Appwrite. Each document has four fields:
| Field | Meaning |
|---|---|
| searchTerm | The keyword users searched |
| count | How many times it was searched |
| movie_id | The TMDB movie ID |
| poster_url | The poster image URL |
The logic is simple:
- Look for an existing document with
Query.equal() - If it exists, increase the count
- If not, create a new document
Here is a simplified version of the idea:
const result = await database.listDocuments(DATABASE_ID, TABLE_ID, [
Query.equal('searchTerm', searchTerm),
]);
if (result.documents.length > 0) {
const doc = result.documents[0];
await database.updateDocument(DATABASE_ID, TABLE_ID, doc.$id, {
count: doc.count + 1,
});
} else {
await database.createDocument(DATABASE_ID, TABLE_ID, ID.unique(), {
searchTerm,
count: 1,
movie_id: movie.id,
poster_url: `https://image.tmdb.org/t/p/w500${movie.poster_path}`,
});
}
How the Flow Works
Ideas for the Next Round
These are improvements I want to try on my own. They go beyond the tutorial.
- Debounce the input. Wait until the user stops typing before calling the API. This cuts down on extra requests.
- Normalize search terms. Trim spaces and use lowercase. “Batman” and “batman “ should count as one term.
- Ignore stale responses. If an older request finishes late, it should not overwrite newer results.
- Show loading and error states. Users should always know what is happening.
What I Learned
- Fetching and rendering API data in React
- Building reusable components
- Managing controlled inputs
- Using Appwrite as a backend service
- Handling missing or partial API data gracefully
Final Thoughts
Following a tutorial is a great way to start. But the real learning begins when you ask why each piece exists.
Search optimization is not only about speed. It is about trust. Clean input handling, safe fallbacks, and useful data make a search feel reliable.
Start simple, then improve one step at a time.
Credits
- This project was built by following a JavaScript Mastery tutorial on YouTube: https://www.youtube.com/watch?v=dCLhUialKPQ
- Movie data is provided by the TMDB API
- Backend service is provided by Appwrite


