@@ -335,21 +335,6 @@ public function addSearchFilter($term)
335335
336336 $ tagPostIds = array_unique ($ tagPostIds );
337337
338- $ mySqlItems = [
339- ' as ' ,
340- 'life ' ,
341- 'guard '
342- ];
343-
344- $ advancedSortingEnabled = true ;
345- $ tmpTerm = ' ' . trim (trim ($ term ), '!.?:, ' ) . ' ' ;
346- foreach ($ mySqlItems as $ item ) {
347- if (false !== stripos ($ tmpTerm , $ item )) {
348- $ advancedSortingEnabled = false ;
349- break ;
350- }
351- }
352-
353338 if ($ tagPostIdsCount = count ($ tagPostIds )) {
354339 $ this ->addFieldToFilter (
355340 ['title ' , 'short_content ' , 'content ' , 'post_id ' ],
@@ -361,24 +346,19 @@ public function addSearchFilter($term)
361346 ]
362347 );
363348
364- if ($ advancedSortingEnabled ) {
349+ if ($ tagPostIdsCount > 200 ) {
350+ $ tagPostIds = array_slice ($ tagPostIds , 0 , 200 );
351+ }
365352
366- if ($ tagPostIdsCount > 200 ) {
367- $ tagPostIds = array_slice ($ tagPostIds , 0 , 200 );
368- }
353+ $ fullExpression = '(0 ' .
354+ '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
355+ . $ this ->getConnection ()->quote ($ term )
356+ . '), 4) ' .
357+ '+ IF(main_table.post_id IN ( ' . implode (', ' , $ tagPostIds ) . '), "1", "0")) ' ;
369358
370- $ this ->addExpressionFieldToSelect (
371- 'search_rate ' ,
372- '(0 ' .
373- '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ("{{term}}"), 4) ' .
374- '+ IF(main_table.post_id IN ( ' . implode (', ' , $ tagPostIds ) . '), "1", "0")) ' ,
375- [
376- 'term ' => $ this ->getConnection ()->quote ($ term )
377- ]
378- );
379- } else {
380- $ this ->addExpressionFieldToSelect ('search_rate ' , ' publish_time ' , []);
381- }
359+ $ fullExpression = new \Zend_Db_Expr ($ fullExpression );
360+ $ this ->getSelect ()->columns (['search_rate ' => $ fullExpression ]);
361+ //$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
382362 } else {
383363 $ this ->addFieldToFilter (
384364 ['title ' , 'short_content ' , 'content ' ],
@@ -389,18 +369,14 @@ public function addSearchFilter($term)
389369 ]
390370 );
391371
392- if ($ advancedSortingEnabled ) {
393- $ this ->addExpressionFieldToSelect (
394- 'search_rate ' ,
395- '(0 ' .
396- '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ("{{term}}"), 4)) ' ,
397- [
398- 'term ' => $ this ->getConnection ()->quote ($ term )
399- ]
400- );
401- } else {
402- $ this ->addExpressionFieldToSelect ('search_rate ' , ' publish_time ' , []);
403- }
372+ $ fullExpression = '(0 ' .
373+ '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ( '
374+ . $ this ->getConnection ()->quote ($ term )
375+ . '), 4)) ' ;
376+
377+ $ fullExpression = new \Zend_Db_Expr ($ fullExpression );
378+ $ this ->getSelect ()->columns (['search_rate ' => $ fullExpression ]);
379+ //$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
404380 }
405381
406382 return $ this ;
0 commit comments