Start a Project

Bagisto Search Engines: How Bagisto Search Makes Integration Possible

bagisto-search-engines-featured-dark-1

Plug any search engine into your Bagisto store without touching the search code. Bagisto Search Engines puts every engine behind one contract and one manager.

What Bagisto Search Engines Change

The Bagisto 2.5 release specifically rebuilt product search around two patterns: Strategy and Manager.

Where Bagisto 2.4 Fell Short

First, look at the old design. In Bagisto 2.4 the product repository held the engine name as a string and checked it everywhere:

  1. Repeated branches: four repository methods carried the same check, so a new method could easily forget it.
  2. Hard-wired engine: the repository took the Elasticsearch repository in its constructor; as a result, no other engine fit in.
  3. Settings in .env only: the Elasticsearch host and credentials could not change without server access.
  4. No connection check: consequently, a wrong host only showed up as failed searches on the storefront.

How Bagisto Search Engines Work

One Contract for Every Engine

An engine implements four methods: search, suggestions, slug lookup and maximum price. Therefore, the repository calls only those.

Similarly, indexing has its own contract, SearchIndexer: index a batch, delete a batch, and reindex everything.

One Manager Picks the Engine

Instead of naming a class, callers now ask the manager for the engine of the current context:

To decide, the manager reads a master switch, a default engine, and one search mode for each side of the store:

As a result, a mode left on Use Default takes the default engine. With the switch off, every search runs on the database, and indexing gets a null indexer.

Connections in Bagisto Search Engines

In addition, an engine that needs a server binds a SearchEngineConnection: configure, probe, and compare with the saved settings.

Then, Test Connection probes the values on screen. If it fails, the result names its cause: unreachable, unauthorized, incompatible or misconfigured.

Moreover, the verdict is cached for five minutes, and only when it matches the saved settings, so unsaved tests never change it.

Extend Bagisto Search Engines

For example, take Algolia. The same steps also fit Typesense, Meilisearch or OpenSearch.

Five Pieces of an Engine

  1. The engine: a class that implements SearchEngine and maps each method to Algolia queries.
  2. The indexer: a class that implements SearchIndexer and pushes product records to Algolia.
  3. The connection: optionally, implement SearchEngineConnection and Test Connection works for Algolia too.
  4. The name: one new case in the SearchEngineEnum PHP enum, plus a settings section for its keys.
  5. The bindings: register each class under the engine name in the Laravel container, from your service provider.

Name and Bind the Engine

Next, give the engine its name, and then register its classes:

What the Admin Sees

After that, Bagisto Search Engines lists it in the admin dropdowns, the manager resolves it, and its settings apply on boot.

The screens below show an example Algolia engine. In contrast, Bagisto core ships with the database and Elasticsearch engines.

Likewise, its settings page follows the same layout as Elasticsearch, with the fields your connection class reads and the same Test Connection button.

Swap an Existing Engine

However, the enum lives in Bagisto core, so a new name goes in as a core change or pull request. Swapping an engine needs none.

For example, an OpenSearch package can bind its own class to the Elasticsearch alias, and every search in the store follows it.

Build It with Agent Skills

Finally, build the engine faster with Bagisto Agent Skills. They teach your AI assistant the package structure, bindings, config and tests.

So when you ask it to scaffold the Algolia engine package, it follows Bagisto’s conventions instead of guessing them.

Works with Bagisto extensions:

  1. Multi Vendor Marketplace: transform your store into a marketplace.
  2. Multi Tenant Commerce: a SaaS solution to launch and scale online.
  3. Headless eCommerce: API-first, flexible headless commerce.
  4. B2B Commerce: build B2B with bulk orders and catalogs.
  5. B2B Marketplace: launch a B2B marketplace for scalable trade.
  6. Mobile App: a customizable open-source eCommerce app.
  7. Bagisto Themes: pre-built stores for every business type.
  8. POS: sell in your offline store and online.
    ….. all other Extensions.

Bagisto Search Engines FAQ

Does a new engine need a change in Bagisto core?

A new engine name does, because the list of engines is an enum in core. Replacing the class behind an existing name does not.

Can the admin panel and the storefront use different engines?

Yes, because Admin Search Mode and Storefront Search Mode are separate settings. As a result, the manager resolves each context on its own.

What does Test Connection check?

First, it asks the engine through its connection class, with the values on screen. Then it reports the status, host, version and cluster name.

How do I fill a new engine’s index?

Run php artisan indexer:index –type=search –mode=full. After that, it calls the active engine’s indexer, whichever engine that is.

Go Ahead with Bagisto

In short, Bagisto Search Engines keeps search code free of engine names, so a new engine is a class and a binding, not a rewrite.

Get started today: Follow the Search Engines guide.

Exit mobile version