Skip to main content

Laravel Scout Full-Text Search

Implement full-text search with Laravel Scout using Meilisearch or Algolia, with faceted filtering, custom ranking, and typo-tolerant search.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI implement a full-text search system with Laravel Scout, spanning [record_count] records across [model_count] models using [search_engine]. It configures Scout, sets [queue_setting] indexing, and tunes global settings like [typo_tolerance], stop words for [language], and [ranking_rules]. Stating the record count and engine lets the AI size the index and plan reindexing rather than producing a setup that works on a handful of rows but stalls at scale.

The structure works because good search is the sum of these decisions. Each model in [searchable_models] gets a toSearchableArray() using [field_strategy] with flattened relationships and shouldBeSearchable() to skip [exclude_criteria]; per-index settings define [facet_fields], [sort_fields], and [synonym_groups]; the API exposes [search_features] like facet counts and suggestions; and a [frontend_component] debounced at [debounce_ms] drives the UX. The optimization step targets [latency_target] and zero-downtime reindexing via [reindex_strategy]. Declaring [record_count] and [queue_setting] lets the AI decide between sync and queued indexing and size scout:import chunks with [chunk_size] so a full reindex does not exhaust memory. The SearchController exposes the [search_features] you ask for — multi-index search, facet counts, highlighted snippets, and did-you-mean suggestions for zero-result queries — and the [debounce_ms] setting on the [frontend_component] keeps the instant-results dropdown from firing a request on every keystroke. Edge cases like soft-deleted records and polymorphic search are handled explicitly rather than left to break later.

When to use it

  • You need fast, typo-tolerant search across multiple models in a Laravel app
  • You want faceted filtering and facet counts in a search sidebar
  • You need queued indexing in production with sync indexing locally
  • You want did-you-mean suggestions for zero-result queries
  • You need zero-downtime reindexing after a data migration
  • You want to keep search latency low by trimming the index payload deliberately

Example output

The AI returns Scout and [search_engine] configuration, toSearchableArray() and shouldBeSearchable() implementations for each model in [searchable_models], per-index settings for searchable attributes, [facet_fields], [sort_fields], and [synonym_groups], a SearchController with multi-index search, facet counts, highlighted snippets, and suggestions, a [frontend_component] with debounced input and a faceted sidebar, plus optimization steps including index warming, scout:import with chunk size [chunk_size], and [reindex_strategy] for zero-downtime reindexing.

Pro tips

  • Order [field_strategy] weights so titles outrank body text; relevance is mostly attribute priority
  • Trim stored attributes toward [size_reduction_target] — excluding body HTML is what keeps [latency_target] reachable
  • Define [synonym_groups] for your domain (JS/JavaScript, auth/authentication) so searchers find results regardless of phrasing
  • Use shouldBeSearchable() with [exclude_criteria] so drafts and archived records never leak into results
  • Tune [chunk_size] for scout:import to balance reindex speed against memory on your box
  • Always plan [reindex_strategy] (index swapping) so a full reindex never serves empty results to live users

Frequently Asked Questions

Does this work with both Meilisearch and Algolia?
Yes. You set the driver in `[search_engine]`; the default is Meilisearch, but the same Scout-based structure applies to Algolia. The per-index settings for ranking, facets, and synonyms map onto whichever engine you choose.
How does it keep drafts and private records out of search?
Each model implements `shouldBeSearchable()` to exclude records matching `[exclude_criteria]`, such as draft posts, archived pages, and private documentation. That keeps unpublished content out of the index even though the model is otherwise searchable.
Can I reindex without taking search offline?
Yes. The optimization step uses `[reindex_strategy]`, defaulting to index swapping with a temporary index, so a full `scout:import` builds in the background and atomically replaces the live index. Users keep getting results throughout the reindex.
How does it keep search latency low?
It trims stored attributes toward `[size_reduction_target]` by excluding large fields like body HTML, warms the index on deploy, and targets `[latency_target]`. Smaller stored payloads and ordered ranking rules are the main levers for fast responses.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support