# Magento

The `warpsearch/module-search` module indexes your product catalog into a WarpSearch collection and adds a storefront quick-search dropdown backed by it. It supports Magento Open Source and Adobe Commerce 2.4.6 to 2.4.8 on PHP 8.2 to 8.4, is available from [Packagist](https://packagist.org/packages/warpsearch/module-search) and is open source (MIT) on [GitHub](https://github.com/warpsearchio/warpsearch-magento).

## Install

```bash
composer require warpsearch/module-search
bin/magento module:enable WarpSearch_Search
bin/magento setup:upgrade && bin/magento setup:di:compile
```

1. Create a collection and a writer key as described in the [shared setup](integrations.md).
2. Go to **Stores > Configuration > WarpSearch > Search** and set **Enable** to Yes (per store view), the API key, the collection and the index name.
3. Make sure the queue consumer runs, then run `bin/magento warpsearch:reindex`.

## Queue consumer

Changes are queued and written in batches. Cron runs the consumer `warpsearch.product.index`. If you restrict consumers in `app/etc/env.php`, add it:

```php
'cron_consumers_runner' => ['cron_run' => true, 'max_messages' => 1000, 'consumers' => ['warpsearch.product.index']],
```

Or run it by hand with `bin/magento queue:consumers:start warpsearch.product.index`. Setting **Index through the message queue** to No indexes inside the save request instead.

## What is indexed

One document per product per store view. A product is indexed only if it is assigned to the store's website, enabled, visible in search, and in stock (unless the store shows out-of-stock products). Otherwise its document is deleted.

Configurable, bundle and grouped parents carry their children's SKUs and names as searchable text, plus the min and max price. Searchable attributes are indexed as text and filterable ones as keywords.

## Reindex command

```bash
bin/magento warpsearch:reindex [--store=code] [--ids=1,2,3] [--batch=100] [--queue]
```

It checks the collection first and exits with code 1 if any document failed. Run it periodically for changes that fire no events: catalog price rules, special price expiry, and imports that bypass the model layer.

## Storefront

The module adds a dropdown to Magento's `#search` input. It calls `/warpsearch/search/suggest`, a server-side route that holds the key and reads names, URLs, images and prices from Magento, so the key never reaches the browser and stale entries never show. On any error the dropdown closes and Magento's own autocomplete takes over.

The `/catalogsearch/result` page and layered navigation still use Magento's own engine. A full engine replacement is planned for a later version.

## Good to know

- Customer-group and tier pricing and multi-source inventory are not modelled. Prices are for logged-out shoppers.
- Text analysis is a global setting, not per store view.
