@@ -386,26 +386,13 @@ public function addSearchFilter($term)
386
386
387
387
$ tagPostIds = array_unique ($ tagPostIds );
388
388
389
- /* Field => Weigth */
390
- $ searchFields = [
391
- 'title ' => 3 ,
392
- 'content ' => 1
393
- ];
394
- $ likeTerm = ['like ' => '% ' . $ term . '% ' ];
395
-
396
- $ formatMatchSql = '0 ' ;
397
- foreach ($ searchFields as $ field => $ fieldWeight ) {
398
- $ formatMatchSql .= '+ FORMAT(MATCH ( ' . $ field . ') AGAINST ( '
399
- . $ this ->getConnection ()->quote ($ term )
400
- . '), 4) * ' . $ fieldWeight . ' ' ;
401
- }
402
-
403
389
if ($ tagPostIdsCount = count ($ tagPostIds )) {
404
390
$ this ->addFieldToFilter (
405
- array_merge ( array_keys ( $ searchFields ), [ ' post_id ' ]) ,
391
+ [ ' title ' , ' short_content ' , ' content ' , ' post_id ' ],
406
392
[
407
- $ likeTerm ,
408
- $ likeTerm ,
393
+ ['like ' => '% ' . $ term . '% ' ],
394
+ ['like ' => '% ' . $ term . '% ' ],
395
+ ['like ' => '% ' . $ term . '% ' ],
409
396
['in ' => $ tagPostIds ]
410
397
]
411
398
);
@@ -414,23 +401,29 @@ public function addSearchFilter($term)
414
401
$ tagPostIds = array_slice ($ tagPostIds , 0 , 200 );
415
402
}
416
403
417
- $ fullExpression = '( ' .
418
- $ formatMatchSql .
404
+ $ fullExpression = '(0 ' .
405
+ '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
406
+ . $ this ->getConnection ()->quote ($ term )
407
+ . '), 4) ' .
419
408
'+ IF(main_table.post_id IN ( ' . implode (', ' , $ tagPostIds ) . '), "1", "0")) ' ;
420
409
421
410
$ fullExpression = new \Zend_Db_Expr ($ fullExpression );
422
411
$ this ->getSelect ()->columns (['search_rate ' => $ fullExpression ]);
423
412
//$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
424
413
} else {
425
414
$ this ->addFieldToFilter (
426
- array_keys ( $ searchFields ) ,
415
+ [ ' title ' , ' short_content ' , ' content ' ] ,
427
416
[
428
- $ likeTerm ,
429
- $ likeTerm
417
+ ['like ' => '% ' . $ term . '% ' ],
418
+ ['like ' => '% ' . $ term . '% ' ],
419
+ ['like ' => '% ' . $ term . '% ' ]
430
420
]
431
421
);
432
422
433
- $ fullExpression = '( ' . $ formatMatchSql . ') ' ;
423
+ $ fullExpression = '(0 ' .
424
+ '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
425
+ . $ this ->getConnection ()->quote ($ term )
426
+ . '), 4)) ' ;
434
427
435
428
$ fullExpression = new \Zend_Db_Expr ($ fullExpression );
436
429
$ this ->getSelect ()->columns (['search_rate ' => $ fullExpression ]);
@@ -740,4 +733,4 @@ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
740
733
}
741
734
return $ this ;
742
735
}
743
- }
736
+ }
0 commit comments