@@ -335,21 +335,6 @@ public function addSearchFilter($term)
335
335
336
336
$ tagPostIds = array_unique ($ tagPostIds );
337
337
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
-
353
338
if ($ tagPostIdsCount = count ($ tagPostIds )) {
354
339
$ this ->addFieldToFilter (
355
340
['title ' , 'short_content ' , 'content ' , 'post_id ' ],
@@ -361,24 +346,19 @@ public function addSearchFilter($term)
361
346
]
362
347
);
363
348
364
- if ($ advancedSortingEnabled ) {
349
+ if ($ tagPostIdsCount > 200 ) {
350
+ $ tagPostIds = array_slice ($ tagPostIds , 0 , 200 );
351
+ }
365
352
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")) ' ;
369
358
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;
382
362
} else {
383
363
$ this ->addFieldToFilter (
384
364
['title ' , 'short_content ' , 'content ' ],
@@ -389,18 +369,14 @@ public function addSearchFilter($term)
389
369
]
390
370
);
391
371
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;
404
380
}
405
381
406
382
return $ this ;
0 commit comments