QI's avatar
Level 1

How to create fast advanced search with big database?

I am looking at implementing the "Advanced Search" from Codyhouse (Laravel 9, vue.js)

https://codyhouse.co/ds/components/app/advanced-search

The search should allow to find everything from thousands of E-Commerce items, Blog articles, Users, Collections, and perhaps even Support docs.

Now I wonder how you would approach this task as searching so many tables and thousands of entries (titles, product images, product descriptions,...) probably will result in a very slow search.

I don't know much about Indexing, Cache etc.

How would you go about this task to still create a fast search?

0 likes
1 reply
LaryAI's avatar
Level 58

To create a fast advanced search with a big database, you can follow these steps:

  1. Use Laravel Scout: Laravel Scout is a powerful search engine that allows you to perform full-text search against your Eloquent models. It uses Algolia, Elasticsearch, or Meilisearch as a search engine. You can easily integrate Laravel Scout into your Laravel application and use it to perform advanced searches.

  2. Use Indexing: Indexing is a technique that allows you to speed up searches by creating an index of your data. When you index your data, you create a data structure that allows you to quickly search for specific data. You can use Laravel Scout to index your data and speed up your searches.

  3. Use Caching: Caching is a technique that allows you to store frequently accessed data in memory. When you cache your data, you store it in memory so that it can be quickly accessed. You can use Laravel's built-in caching system to cache your search results and speed up your searches.

  4. Use Pagination: When you have a large amount of data, it's important to use pagination to limit the number of results returned. This will help to speed up your searches and make them more manageable.

Here's an example of how you can use Laravel Scout to perform an advanced search:

// Perform a search across multiple models
$searchResults = \App\Models\Product::search('query')->get()
    ->merge(\App\Models\Blog::search('query')->get())
    ->merge(\App\Models\User::search('query')->get())
    ->merge(\App\Models\Collection::search('query')->get())
    ->merge(\App\Models\SupportDoc::search('query')->get());

// Paginate the results
$results = $searchResults->paginate(10);

In this example, we're performing a search across multiple models using Laravel Scout. We're then merging the results and paginating them to limit the number of results returned.

Please or to participate in this conversation.