Skip to content

Commit ed00817

Browse files
committed
Reverted addSearchFilter
1 parent 342cfa5 commit ed00817

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

Model/ResourceModel/Post/Collection.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -386,26 +386,13 @@ public function addSearchFilter($term)
386386

387387
$tagPostIds = array_unique($tagPostIds);
388388

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-
403389
if ($tagPostIdsCount = count($tagPostIds)) {
404390
$this->addFieldToFilter(
405-
array_merge(array_keys($searchFields), ['post_id']),
391+
['title', 'short_content', 'content', 'post_id'],
406392
[
407-
$likeTerm,
408-
$likeTerm,
393+
['like' => '%' . $term . '%'],
394+
['like' => '%' . $term . '%'],
395+
['like' => '%' . $term . '%'],
409396
['in' => $tagPostIds]
410397
]
411398
);
@@ -414,23 +401,29 @@ public function addSearchFilter($term)
414401
$tagPostIds = array_slice($tagPostIds, 0, 200);
415402
}
416403

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) ' .
419408
'+ IF(main_table.post_id IN (' . implode(',', $tagPostIds) . '), "1", "0"))';
420409

421410
$fullExpression = new \Zend_Db_Expr($fullExpression);
422411
$this->getSelect()->columns(['search_rate' => $fullExpression]);
423412
//$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
424413
} else {
425414
$this->addFieldToFilter(
426-
array_keys($searchFields),
415+
['title', 'short_content', 'content'],
427416
[
428-
$likeTerm,
429-
$likeTerm
417+
['like' => '%' . $term . '%'],
418+
['like' => '%' . $term . '%'],
419+
['like' => '%' . $term . '%']
430420
]
431421
);
432422

433-
$fullExpression = '(' . $formatMatchSql . ')';
423+
$fullExpression = '(0 ' .
424+
'+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('
425+
. $this->getConnection()->quote($term)
426+
. '), 4))';
434427

435428
$fullExpression = new \Zend_Db_Expr($fullExpression);
436429
$this->getSelect()->columns(['search_rate' => $fullExpression]);
@@ -740,4 +733,4 @@ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
740733
}
741734
return $this;
742735
}
743-
}
736+
}

0 commit comments

Comments
 (0)