Search & Filtering for AI Coders | SheCodes
Intermediate 5 min read

Search & Filtering for AI Coders

Help users find exactly what they need. Search bars, filters, sorting, and pagination patterns explained in plain English.

In this chapter

  • The difference between search, filters, sorting, and pagination
  • When to use simple text search vs full-text search
  • How to ask AI to add filters that actually work
  • Patterns that make finding things fast and obvious

Search Types

Full-Text Search Searches through all the text content in your database. Like Google, but for your app. Type a word and it finds every item containing that word, even across multiple fields like title and description.
chocolate cake recipe

Best Chocolate Cake Recipe

A rich, moist chocolate cake that's easy to make...

Easy Chocolate Lava Cake

This recipe makes the perfect molten chocolate dessert...

Fuzzy Search Finds results even when the user misspells a word. Search for 'reciepe' and still get 'recipe' results. Great for forgiving typos and improving the user experience.
reciepe
Did you mean:recipe?

Classic Banana Bread Recipe

The best homemade banana bread recipe you'll ever try...

Quick Pasta Recipe for Beginners

A simple 15-minute pasta recipe anyone can make...

Faceted Search Lets users narrow results by categories, like filtering products by price range, color, and brand all at once. Think of Amazon's left sidebar filters.

Price Range

Under $25
$25 - $50
$50+

Color

Blue
Red

Brand

Nike
Adidas

Showing 12 results

Blue Running Shoe - $22
Blue Casual Sneaker - $19
Blue Sport Sandal - $24
Autocomplete Shows suggestions as the user types. A dropdown appears below the search bar with matching results, helping users find things faster and reducing typos.
how to
how to center a div in CSS
how to deploy to Vercel
how to use React hooks
how to add dark mode

Filter Patterns

Sidebar Filters A panel on the left with checkboxes, sliders, and dropdowns. Users select options to narrow results. Common on e-commerce sites and job boards.

Category

Electronics
Clothing
Books

Price Range

$15$70

Rating

4 stars & up
Active Filter Chips Small pill-shaped tags showing what filters are active. Each chip has an 'x' to remove it. Shows users exactly what's applied at a glance.
Electronics Under $50 4+ Stars In Stock
Clear all filters
Sort Dropdown A dropdown menu letting users reorder results: newest first, price low to high, most popular, alphabetical. Usually placed above the results grid.
Sort by:Newest
Newest
Price: Low to High
Price: High to Low
Most Popular
Alphabetical
Pagination Splits results into pages (1, 2, 3...) or loads more items as the user scrolls. Prevents loading thousands of items at once, keeping your app fast.
Search + Filter Combo A search bar at the top combined with filters below. Users type a keyword, then narrow further by category, date, or price. The most powerful pattern.

Search Tools Compared

Meilisearch An open-source alternative to Algolia. Self-host it or use their cloud service. Fast, typo-tolerant search with a simple API. Pros
  • Open source and free to self-host
  • Easy setup with great documentation
  • Typo tolerance and filtering out of the box
Cons
  • Self-hosting requires server management
  • Smaller ecosystem than Algolia
Best for: Developers who want Algolia-like search for free
Fuse.js A lightweight JavaScript library for fuzzy search. Runs entirely in the browser (no server or external service needed). Perfect for small datasets. Pros
  • Zero dependencies, tiny bundle size
  • Works entirely client-side
  • Easy to set up (just import and configure)
Cons
  • Slow with large datasets (1000+ items)
  • No server-side search capability
Best for: Small lists, client-side filtering
Built-in Database Search Use your database's built-in search features (PostgreSQL full-text search, MongoDB text indexes). No external service needed. Pros
  • No extra cost or service to manage
  • Data stays in your database
  • Works with SQL queries you already know
Cons
  • Less feature-rich than dedicated search tools
  • Requires more manual setup for good results
Best for: Simple search on existing database data

Common Patterns

Debounced Search Instead of searching on every keystroke, wait until the user stops typing (usually 300ms). This prevents flooding your server with requests and makes your app feel smoother. Tell AI: 'Add a 300ms debounce to the search input.'
URL-Based Filters Store active filters in the URL (e.g., /products?category=shoes&sort=price). This lets users bookmark filtered views, share links, and use the back button to undo filters. Tell AI: 'Store all filters and search query in URL parameters.'
Empty States What to show when a search returns no results. Display a friendly message like 'No results found for sneakers' with suggestions: check spelling, try different keywords, or clear filters. Never show a blank page.
Loading States Show skeleton loaders or a spinner while search results are loading. Users should always know something is happening. A subtle loading indicator above the results grid works well.

AI Prompts for Search & Filtering

Copy-paste these prompts to quickly add search and filtering features to your project.

“Add a search bar that filters products by name and category. Show results as the user types with a 300ms debounce. Display 'No results found' when nothing matches.”

“Add sidebar filters for price range (slider), category (checkboxes), and rating (star buttons). Show active filters as removable chips above the results.”

“Add a sort dropdown above the product grid with options: Newest, Price Low to High, Price High to Low, and Most Popular. Store the sort selection in the URL.”

“Add pagination to my product listing: show 12 items per page with Previous/Next buttons and page numbers. Keep the current page in the URL so it's bookmarkable.”

“Add autocomplete search using Fuse.js. Show a dropdown with up to 5 matching suggestions as the user types. Clicking a suggestion navigates to that item's page.”

Real World Example: Recipe Search & Filtering

Imagine you're building a recipe app with 100+ recipes. Users want to search by name ('chicken pasta'), filter by category (Breakfast, Lunch, Dinner, Dessert), filter by cooking time (under 30 min, 30-60 min, 60+ min), and sort by newest or most popular. The filters should combine, so 'chicken' + 'Dinner' + 'under 30 min' shows only quick chicken dinners.

Build this with AI

“Build a recipe search and filtering page. Show recipes as cards in a grid (image, title, category badge, cooking time, rating). Add a search bar that filters by title in real-time. Add filter dropdowns for category (Breakfast, Lunch, Dinner, Dessert, Snack) and cooking time (Under 30 min, 30-60 min, Over 60 min). Add sort options (Newest, Most Popular, Quickest). All filters should combine together. Show 'No recipes found' when nothing matches. Use 15 sample recipes with realistic data. Style with Tailwind CSS.”

Frequently Asked Questions

Should search happen on the frontend or backend?

For small datasets (under ~500 items), frontend filtering is fine. It's instant and doesn't need API calls. For larger datasets, use backend search with database queries. Libraries like Fuse.js handle frontend fuzzy search well.

How do I add search that works as users type?

Add a debounce (a short delay of 200-300ms after the user stops typing) before running the search. This prevents running a search on every keystroke. Tell your AI tool to add debounced search and it will handle the timing.

How do I keep filters in the URL so users can share searches?

Store filter values as URL search parameters (like ?category=shoes&sort=price). This way users can bookmark or share filtered views. In Next.js, use useSearchParams to read and update URL parameters. Your AI tool can set this up.