@@ -28,6 +28,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
2828 */
2929 protected $ _eventObject = 'blog_post_collection ' ;
3030
31+ /**
32+ * @var string[]
33+ */
34+ protected $ _ftiCollumns = ['title ' , 'meta_keywords ' , 'meta_description ' , 'identifier ' , 'content ' ];
35+
3136 /**
3237 * @var \Magento\Store\Model\StoreManagerInterface
3338 */
@@ -103,7 +108,6 @@ protected function _construct()
103108 $ this ->_map ['fields ' ]['store ' ] = 'store_table.store_id ' ;
104109 $ this ->_map ['fields ' ]['category ' ] = 'category_table.category_id ' ;
105110 $ this ->_map ['fields ' ]['tag ' ] = 'tag_table.tag_id ' ;
106- $ this ->_map ['fields ' ]['tag ' ] = 'tag_table.tag_id ' ;
107111 $ this ->_map ['fields ' ]['relatedproduct ' ] = 'relatedproduct_table.related_id ' ;
108112 }
109113
@@ -401,10 +405,7 @@ public function addSearchFilter($term)
401405 $ tagPostIds = array_slice ($ tagPostIds , 0 , 200 );
402406 }
403407
404- $ fullExpression = '(0 ' .
405- '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
406- . $ this ->getConnection ()->quote ($ term )
407- . '), 4) ' .
408+ $ fullExpression = $ this ->getSearchRateExpression ($ term , $ this ->_ftiCollumns ) .
408409 '+ IF(main_table.post_id IN ( ' . implode (', ' , $ tagPostIds ) . '), "1", "0")) ' ;
409410
410411 $ fullExpression = new \Zend_Db_Expr ($ fullExpression );
@@ -420,19 +421,25 @@ public function addSearchFilter($term)
420421 ]
421422 );
422423
423- $ fullExpression = '(0 ' .
424- '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
425- . $ this ->getConnection ()->quote ($ term )
426- . '), 4)) ' ;
427-
428- $ fullExpression = new \Zend_Db_Expr ($ fullExpression );
424+ $ fullExpression = new \Zend_Db_Expr ($ this ->getSearchRateExpression ($ term , $ this ->_ftiCollumns ));
429425 $ this ->getSelect ()->columns (['search_rate ' => $ fullExpression ]);
426+
430427 //$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
431428 }
432429
433430 return $ this ;
434431 }
435432
433+ /**
434+ * @param $term
435+ * @param array $columns
436+ * @return string
437+ */
438+ public function getSearchRateExpression ($ term , array $ columns ): string
439+ {
440+ return '(0 + FORMAT(MATCH ( ' . implode (', ' , $ columns ) . ') AGAINST ( ' . $ this ->getConnection ()->quote ($ term ) . '), 4)) ' ;
441+ }
442+
436443 /**
437444 * Add tag filter to collection
438445 * @param array|int|string|\Magefan\Blog\Model\Tag $tag
0 commit comments