Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

フロント検索ボックス、商品のタグ名による絞り込み #4976

Closed
wants to merge 2 commits into from

Conversation

matsuoshi
Copy link
Contributor

@matsuoshi matsuoshi commented Mar 19, 2021

概要(Overview・Refs Issue)

4.1-feature 向けのPRです。
フロントの検索ボックスにて、タグ名での検索を行えるようにします
#4862
いったんPR作成しましたが、ちょっとクエリ記述部分が悩ましいのでご意見いただけたらと思います。

方針(Policy)

商品に付与されたタグ名を、検索ボックスからの検索対象にします。

例: 「新商品」タグが付与された商品は、「新商品」という文字列で検索した場合、検索にひっかかるようになる

フロントの見た目・UI変更はありません。

実装に関する補足(Appendix)

管理画面側のタグ検索は別PRにて
#4975

テスト(Test)

タグ名による検索、複数のタグ名でのand検索、タグ名と商品名のand検索、のテストを追加しています

相談(Discussion)

現状の検索処理 ProductRepository の getQueryBuilderBySearchData() では、規格の商品コードを検索対象としています。
今回はそれと同様にタグ名を検索対象とするよう、直後にSQLを追記しました。
が、SQLの記述が長くなってきましてこれで良いのか判断しかねています。

たとえばクエリビルダの expr()->orX() あたりを使って分割・書き換えたほうがよいか、
他になにかよい手があればアドバイスいただきたい感じです

マイナーバージョン互換性保持のための制限事項チェックリスト

  • 既存機能の仕様変更
  • フックポイントの呼び出しタイミングの変更
  • フックポイントのパラメータの削除・データ型の変更
  • twigファイルに渡しているパラメータの削除・データ型の変更
  • Serviceクラスの公開関数の、引数の削除・データ型の変更
  • 入出力ファイル(CSVなど)のフォーマット変更

レビュワー確認項目

  • 動作確認
  • コードレビュー
  • E2E/Unit テスト確認(テストの追加・変更が必要かどうか)
  • 互換性が保持されているか
  • セキュリティ上の問題がないか

新機能追加に伴う競合確認

3件タグ関連のプラグインあり、調査してチェック

@tao-s
Copy link
Contributor

tao-s commented Jul 5, 2021

tag1, tag2, tag3... とするのではなく、 tag[]として配列でタグを渡す方が冗長なコードが無くなると思うんですが、いかがでしょう?

ProductRepository::getQueryBuilderBySearchData()

        // tag
        $tagJoin = false;
        if (!empty($searchData['tag']) && $searchData['tag']) {
            if ($searchData['tag']) {
                foreach($searchData['tag'] as $tkey => $tag)
                {
                    $qb
                    ->innerJoin('p.ProductTag', 'ptg'.$tkey)
                    ->innerJoin('ptg'.$tkey.'.Tag', 'tg'.$tkey)
                    ->andWhere('ptg'.$tkey.'.Tag = :Tags'.$tkey)
                    ->setParameter('Tags'.$tkey, $tag);
                }
                $tagJoin = true;
            }
        }

Form\Type\SearchProdyctType::buildForm()

        $builder->add('tag', EntityType::class, [
            'class' => 'Eccube\Entity\Tag',
            'choice_label' => 'Name',
            'choices' => $Tags,
            'multiple' => true,
            'expanded' => true,
            'placeholder' => 'common.select__all_products',
            'required' => false,
        ]);

@chihiro-adachi chihiro-adachi added this to the 4.1 milestone Aug 26, 2021
@chihiro-adachi chihiro-adachi added the enhancement 機能追加 label Aug 26, 2021
@chihiro-adachi chihiro-adachi modified the milestones: 4.1, 4.1.x Sep 3, 2021
@chihiro-adachi chihiro-adachi changed the base branch from 4.1-feature to 4.1 September 6, 2021 05:39
@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2021

Codecov Report

Merging #4976 (3d76972) into 4.1 (155be68) will decrease coverage by 0.14%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                4.1    #4976      +/-   ##
============================================
- Coverage     68.33%   68.18%   -0.15%     
  Complexity     6033     6033              
============================================
  Files           456      456              
  Lines         24929    24929              
============================================
- Hits          17036    16999      -37     
- Misses         7893     7930      +37     
Flag Coverage Δ
E2E 57.21% <ø> (ø)
Unit 75.61% <ø> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Eccube/Repository/ProductRepository.php 74.23% <ø> (-22.70%) ⬇️
src/Eccube/Entity/ProductImage.php 66.66% <0.00%> (-6.67%) ⬇️
src/Eccube/Entity/TaxRule.php 86.41% <0.00%> (+2.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 155be68...3d76972. Read the comment docs.

@matsuoshi matsuoshi modified the milestones: 4.1.x, 4.1.1 Nov 15, 2021
@nanasess
Copy link
Contributor

nanasess commented Nov 24, 2021

@matsuoshi ユニットテストがすべて落ちているようですので、最新の 4.1 ブランチをマージしてみていただけますでしょうか?
また、 tao さんのコメントご確認お願いします

@matsuoshi matsuoshi force-pushed the feature/tag-search-front branch 4 times, most recently from b53f7f7 to 0d07178 Compare November 25, 2021 08:52
@tao-s
Copy link
Contributor

tao-s commented Nov 25, 2021

@matsuoshi すいません、僕が少し勘違いしていました。
単純にタグを選択して商品を検索するのかと思ってましたが、キーワードでタグを検索するという仕様なんですね。
ただ、この書き方だとキーワードが入力された時のクエリが冗長でパフォーマンスに疑問があります。
ひとつのクエリで全てを処理するのではなく、タグの検索と商品の検索とでクエリを2つに分けるのはどうでしょうか?

@matsuoshi matsuoshi force-pushed the feature/tag-search-front branch 3 times, most recently from 3a69920 to 0f67030 Compare November 26, 2021 00:10
@matsuoshi
Copy link
Contributor Author

@tao-s @nanasess
反応おそくなりすみません、クエリの部分は自分でも不安がありましたのでアドバイス助かります、ありがとうございます。ちょっと検討してみます。

@matsuoshi
Copy link
Contributor Author

こちら、やはりパフォーマンスの懸念と、外部仕様が適切がどうかという所から再検討したいと思います
(タグを検索したいニーズはあるとして、キーワード欄にてタグ名で検索するという仕様が適切か否か?など)
@tao-s ありがとうございました!

@matsuoshi matsuoshi closed this Nov 26, 2021
@tao-s
Copy link
Contributor

tao-s commented Nov 26, 2021

@matsuoshi ウチの事例だと、キーワードじゃなくて、タグをクリックした際にそのタグで絞り込める様な感じで実装しています。

https://kamiol.com/products/list?tag[]=6&tag[]=8&name=%E3%82%AD%E3%83%A5%E3%83%AA%E3%82%A2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 機能追加
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants