web200/magento-elasticsuite-autocomplete

加快自动完成搜索的 Magento 2 模块

安装数: 35,822

依赖项: 0

建议者: 0

安全: 0

星标: 15

关注者: 6

分支: 6

开放问题: 1

类型:magento2-component

v1.3 2024-06-07 14:23 UTC

README

使用 elasticsuite 加快自动完成搜索的 Magento 2 模块

功能

本模块使用

  • Elasticsearch 响应
  • 只加载最少的 Magento 类来显示产品(价格和图片助手)
  • 仅返回产品(带有 additional_attributes)和分类

为了提高速度,我尝试了两种路由方式

  • 默认 Magento 2 路由方式(通过声明 routes.xml 并使用控制器)
  • 无路由方式(在 /pub 目录中使用 search.php 文件)

安装

Composer

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

或 Github

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

复制

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

$MAGENTO_ROOT/pub/

Nginx 规范

# 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$ {

使用

  • 重新索引 Magento 目录
php bin/magento indexer:reindex

如果你克隆了仓库,别忘了复制 /pub/search.php 文件(如果你使用 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() ?>",

基准测试

为了基准测试,我使用了带有示例数据的 Magento 2.4.2 和所有缓存都是激活的。本地 Ubuntu 系统,使用 mysql / elasticsearch / apache(未使用 docker)

结果

  • Elasticsuite 最新版本(2.10.3): 360ms
  • 本模块使用默认 Magento 路由: 120ms
  • 本模块不使用 Magento 路由: 80ms