web200/magento-elasticsuite-autocomplete

Magento 2 Module to speed autocomplete search

Installs: 29 399

Dependents: 0

Suggesters: 0

Security: 0

Stars: 14

Watchers: 6

Forks: 6

Open Issues: 1

Type:magento2-component

v1.2 2024-02-27 08:20 UTC

README

Magento 2 Module to speed autocomplete search with elasticsuite

Features

This module use :

  • Elasticsearch response
  • Load the minimum magento class to display product (price and image helper)
  • Return only products (with additional_attributes), categories

To improve speed I try two ways of routing :

  • Default magento 2 routing way (by declaring routes.xml and use controller)
  • No routing way (use a search.php file in /pub directory)

Installation

Composer

$ composer require "web200/magento-elasticsuite-autocomplete":"*"

Or Github

git clone git@github.com:Web200/magento-elasticsuite-autocomplete.git

Copy

$MAGENTO_ROOT/app/code/Web200/ElasticsuiteAutocomplete/pub/search.php

in

$MAGENTO_ROOT/pub/

Nginx specification

# Defaut magento installation (Nginx) protect php script execution, you need to edit your virtualhost like this :
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
# =>
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check|search)\.php$ {

Use

  • Reindex Magento Catalog
php bin/magento indexer:reindex

If you clone the repository don't forget to copy /pub/search.php file (file is copied automatically if you use composer install)

# To test the module you only need to install it, and edit this file (by overriding in your theme module):
# smile/elasticsuite/src/module-elasticsuite-core/view/frontend/templates/search/form.mini.phtml

# Default elasticsuite module :
"url":"<?php /* @escapeNotVerified */ echo $block->getUrl('search/ajax/suggest'); ?>",
# This Module with default magento routing :
"url":"<?php /* @escapeNotVerified */ echo $block->getUrl('autocomplete'); ?>",
# This Module without magento routing : 
"url":"<?= $block->getFormViewModel()->getSearchUrl() ?>",

Benchmarks

For benchmarking, I use Magento 2.4.2 with sample data and all cache are active. Local ubuntu with mysql / elasticsearch / apache (no docker use)

Results :

  • Elasticsuite last version (2.10.3) : 360ms
  • This Module with default magento routing : 120ms
  • This Module without magento routing : 80ms