Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
フロント画面商品検索で、ひらがなとカタカナ、アルファベット大文字と小文字を区別せず検索するよう変更 #1792
  • Loading branch information
izayoi256 committed Sep 29, 2016
1 parent d8324b8 commit 89665dc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Eccube/Application.php
Expand Up @@ -478,7 +478,10 @@ public function initDoctrine()

$this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array(
'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine/proxies',
'orm.em.options' => $options
'orm.em.options' => $options,
'orm.custom.functions.string' => array(
'NORMALIZE' => 'Eccube\Doctrine\ORM\Query\Normalize',
),
));

/**
Expand Down
56 changes: 56 additions & 0 deletions src/Eccube/Doctrine/ORM/Query/Normalize.php
@@ -0,0 +1,56 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2016 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Eccube\Doctrine\ORM\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

/**
* @package Eccube\Doctrine\ORM\Query
*/
class Normalize extends FunctionNode
{
protected $string;
const FROM = 'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉっゃゅょわいえー';
const TO = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォッャュョヮヰヱー';

public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->string = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(SqlWalker $sqlWalker)
{
if ($sqlWalker->getConnection()->getDriver()->getName() == 'pdo_pgsql') {
return sprintf("LOWER(TRANSLATE(%s, '%s', '%s'))", $this->string->dispatch($sqlWalker), self::FROM, self::TO);
} else {
return sprintf('%s COLLATE utf8_unicode_ci', $this->string->dispatch($sqlWalker));
}
}
}
2 changes: 1 addition & 1 deletion src/Eccube/Repository/ProductRepository.php
Expand Up @@ -98,7 +98,7 @@ public function getQueryBuilderBySearchData($searchData)
foreach ($keywords as $index => $keyword) {
$key = sprintf('keyword%s', $index);
$qb
->andWhere(sprintf('p.name LIKE :%s OR p.search_word LIKE :%s', $key, $key))
->andWhere(sprintf('NORMALIZE(p.name) LIKE NORMALIZE(:%s) OR NORMALIZE(p.search_word) LIKE NORMALIZE(:%s)', $key, $key))
->setParameter($key, '%' . $keyword . '%');
}
}
Expand Down

0 comments on commit 89665dc

Please sign in to comment.