1

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\DB\Helper\Mysql\Fulltext" type="Vendor\Module\Helper\Mysql\Fulltext" />
</config>

Fulltext.php

namespace Vendor\Module\Helper\Mysql;

use Magento\Framework\App\ResourceConnection;

class Fulltext extends \Magento\Framework\DB\Helper\Mysql\Fulltext
{
    /**
     * @param ResourceConnection $resource
     */
    public function __construct(ResourceConnection $resource)
    {
        $this->conn = $resource->getConnection();
    }

    public function getMatchQuery($columns, $expression, $mode = self::FULLTEXT_MODE_NATURAL)
    {
        if(is_array($columns) && count($columns) > 1)
            return parent::getMatchQuery($columns, $expression, $mode);

        $columns = is_array($columns) ? array_pop($columns):$columns;
        $expression = str_replace('*', '', $expression);
        $expression = str_replace('%', '%%', $expression);
        $expression = $this->conn->quote('%'.$expression.'%');

        $condition = $columns.' LIKE '.$expression;
        return $condition;
    }
}

Module代码

http://git.oschina.net/willia...


猫之良品
2.5k 声望139 粉丝

资深Drupal, magento与Joomla


« 上一篇
常用的git指令
下一篇 »
magento2 plugin

引用和评论

1 篇内容引用
0 条评论