Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Kaliop/MirasvitSearch/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Kaliop/MirasvitSearch/Plugin/EmptySearchQueryPlugin.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * <[email protected]>
 */

declare(strict_types=1);

namespace Kaliop\MirasvitSearch\Plugin;

use Magento\Framework\Search\Adapter\Mysql\ResponseFactory;
use Magento\Framework\Search\Request\QueryInterface;
use Magento\Framework\Search\RequestInterface;
use Magento\Framework\Search\Response\Bucket;
use Magento\Framework\Search\Response\QueryResponse;
use Magento\Framework\Search\ResponseInterface;
use Magento\Framework\Search\SearchEngineInterface;

class EmptySearchQueryPlugin
{
//    /**
//     * @var ResponseFactory
//     */
//    private $responseFactory;
//
//    /**
//     * @param ResponseFactory $responseFactory
//     */
//    public function __construct(
//        ResponseFactory $responseFactory
//    ) {
//        $this->responseFactory = $responseFactory;
//    }
//
//    /**
//     * @param SearchEngineInterface $subject
//     * @param ResponseInterface $result
//     * @param RequestInterface $request
//     * @return QueryResponse|ResponseInterface
//     */
//    public function afterSearch(
//        SearchEngineInterface $subject,
//        ResponseInterface $result,
//        RequestInterface $request
//    ): ResponseInterface {
//        if ($request->getName() == 'quick_search_container' &&
//            !$this->hasSearchQuery($request)) {
//            return $this->responseFactory->create($this->getEmptyResult($result));
//        }
//
//        return $result;
//    }
//
//    /**
//     * @param RequestInterface $request
//     * @return bool
//     */
//    private function hasSearchQuery(RequestInterface $request): bool
//    {
//        $query = $request->getQuery();
//        if ($query->getType() == QueryInterface::TYPE_BOOL) {
//            return isset($query->getShould()['search'])
//                && !empty($query->getShould()['search']);
//        }
//    }
//
//    /**
//     * @param QueryResponse $response
//     * @return array
//     */
//    private function getEmptyResult(QueryResponse $response): array
//    {
//        $aggregations = [];
//        /** @var Bucket $aggregation */
//        foreach ($response->getAggregations() as $aggregation) {
//            $aggregations[$aggregation->getName()] = [];
//        }
//
//        return [
//            'documents' => [],
//            'aggregations' => $aggregations,
//            'total' => 0,
//        ];
//    }
}

Spamworldpro Mini