Skip to content

Commit c90edaa

Browse files
glo80326glo71317
authored andcommitted
BUG#AC-932: Performance issue and scalability of popular search term cache
1 parent 34e15a1 commit c90edaa

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

app/code/Magento/Search/Model/ResourceModel/Query/Collection.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Data\Collection\EntityFactoryInterface;
1010
use Magento\Framework\DB\Adapter\AdapterInterface;
1111
use Magento\Framework\DB\Helper;
12+
use Magento\Framework\DB\Select;
1213
use Magento\Framework\Event\ManagerInterface;
1314
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1415
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
@@ -116,21 +117,22 @@ public function getStoreId()
116117
*/
117118
public function setQueryFilter($query)
118119
{
119-
$this->getSelect()->reset(
120-
\Magento\Framework\DB\Select::FROM
121-
)->distinct(
122-
true
123-
)->from(
124-
['main_table' => $this->getTable('search_query')]
125-
)->where(
126-
'num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?',
127-
$this->_resourceHelper->addLikeEscape($query, ['position' => 'start'])
128-
)->order(
129-
'popularity ' . \Magento\Framework\DB\Select::SQL_DESC
130-
);
120+
$this->getSelect()
121+
->reset(Select::FROM)
122+
->distinct(true)
123+
->from(['main_table' => $this->getTable('search_query')])
124+
->reset(Select::COLUMNS)
125+
->columns(['query_text', 'num_results', 'popularity'])
126+
->where(
127+
'num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?',
128+
$this->_resourceHelper->addLikeEscape($query, ['position' => 'start'])
129+
)
130+
->order('popularity ' . \Magento\Framework\DB\Select::SQL_DESC);
131+
131132
if ($this->getStoreId()) {
132133
$this->getSelect()->where('store_id = ?', (int)$this->getStoreId());
133134
}
135+
134136
return $this;
135137
}
136138

0 commit comments

Comments
 (0)