freento/fast-search-autocomplete
Composer 安装命令:
composer require freento/fast-search-autocomplete
包简介
Freento Fast Search Autocomplete
README 文档
README
Magento's autocomplete feature works quite slowly. Users expect almost instant responses when entering text in the search input. Additionally, Magento does not display products as a result of search queries.
Module Goal - Achieve near-instant input, around 50ms.
Additional goal - display products as a result of search queries.
Plan to achieve the goals:
- Abandon auxiliary SQL queries, implement only with Elastic.
- Avoid additional network interactions (Redis, SQL).
- Avoid Magento bootstrap.
Installation
- Install module:
composer require freento/fast-search-autocomplete - Run magento commands:
bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
- To populate the attribute required for operation take an action of your choice:
- Run CLI command
bin/magento freento:fsa:fillname. - Wait for the "freento_fastsearchautocomplete_fill_original_name" cron job execution (it runs once a day).
- Run CLI command
- Reindex or wait for Magento to do it automatically.
Module Operation Modes
Fast Mode (Direct Elastic)
All Magento AJAX controller queries are quite slow because they do not trigger FPC and:
- Go through Magento bootstrap, composer autoload.
- Require caching data retrieval from Redis or the file system.
- Perform about a dozen MySQL queries.
For example, the simplest native Magento search query for autocomplete makes about 30 Redis and 10 MySQL queries and takes 135 milliseconds.
Our module has a Fast mode that makes a direct request to Elasticsearch without invoking Magento's bootstrap. This is achieved by uploading a simple script to the server's pub folder responsible for high-speed operation. The response from Magento comes in tens of milliseconds.
Demo: Fast Search Autocomplete Demo
Basic module setup:
- Switch the module to "Direct Elastic" mode. (Stores > Configuration > Freento > Fast Search Autocomplete > General > Mode)
- Generate a configuration file. (Stores > Configuration > Freento > Fast Search Autocomplete > General > Generate Search Configuration File)
- Copy the basic file from the misc folder of the extension to the pub folder (
pub/search_result.php), which does not bootstrap Magento but works directly with Elasticsearch. - Adjust the server configuration to allow the module to access the file from step 3. Example from nginx.conf:
...
# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check|search_result)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
Native Magento mode
It operates similarly to the "Direct Elastic" mode but involves Magento's bootstrap, which is not very fast and also makes additional MySQL and Redis queries. To switch to this mode, simply select "Native Magento" under Stores - Configuration - Fast Search Autocomplete.
Technical Notes
Attribute
Since Elasticsearch stores names for configurable and bundle products as a string containing the names of all included simples, a separate attribute was added to display normal product names in the results. This attribute is filled in when a product is saved or through the cron job freento_fastsearchautocomplete_fill_original_name or by running the CLI command
bin/magento freento:fsa:fillname.
Without filling this attribute, the search will not work correctly.
Redirect to Product Page
To navigate to a product page, the product's ID is used instead of a direct link. When a result is clicked, it redirects to a controller where the product's page URL is generated based on the product's ID (or a noroute page if the product cannot be found by ID), and then redirects to the correct page.
Fast mode specifics
The search occurs in the pub/search_result.php file. If you need more flexible rules for the Elastic request, you can modify the file, but usually it is not required and autogenerated file is fine. Magento's indexer does not store product URLs. In the popup, there are links to an intermediate controller, and upon navigating to it, the correct product URL is determined, and a redirect to the correct page occurs.
The file uses a generated config file with the following fields. If there are any errors when connecting to Elasticsearch, check this file (var/freento-elastic-config.json).
Configuration file sample:
{
"hostname": "localhost",
"port": "9200",
"index": "magento2",
"enableAuth": "0",
"username": "",
"password": "",
"timeout": "15",
"engine": "opensearch",
"max_results_count": "10"
}
freento/fast-search-autocomplete 适用场景与选型建议
freento/fast-search-autocomplete 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 freento/fast-search-autocomplete 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freento/fast-search-autocomplete 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-09-05