Skip to content

Commit 7e8f730

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-2101' into PR_06_SEP_2023
2 parents 51e8d90 + ad4cd7a commit 7e8f730

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public function setPopularQueryFilter($storeIds = null)
150150

151151
$storeIds = $storeIds ?: $this->_storeManager->getStore()->getId();
152152
$this->addStoreFilter($storeIds);
153-
$this->getSelect()->where('num_results > 0');
153+
$this->getSelect()->where('main_table.num_results > 0');
154154

155-
$this->getSelect()->order(['popularity desc']);
155+
$this->getSelect()->order(['main_table.popularity desc']);
156156

157157
return $this;
158158
}
@@ -174,8 +174,8 @@ public function isTopSearchResult(string $term, int $storeId, int $maxCountCache
174174
$select->distinct(true);
175175
$select->from(['main_table' => $this->getTable('search_query')], ['query_text']);
176176
$select->where('main_table.store_id IN (?)', $storeId);
177-
$select->where('num_results > 0');
178-
$select->order(['popularity desc']);
177+
$select->where('main_table.num_results > 0');
178+
$select->order(['main_table.popularity desc']);
179179

180180
$select->limit($maxCountCacheableSearchTerms);
181181

@@ -208,7 +208,7 @@ public function setRecentQueryFilter()
208208
public function addStoreFilter($storeIds)
209209
{
210210
$condition = is_array($storeIds) ? 'main_table.store_id IN (?)' : 'main_table.store_id = ?';
211-
$this->getSelect()->where($condition, $storeIds);
211+
$this->getSelect()->where($condition, $storeIds, \Zend_Db::INT_TYPE);
212212

213213
return $this;
214214
}

app/code/Magento/Search/etc/db_schema.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@
4040
<column name="store_id"/>
4141
<column name="popularity"/>
4242
</index>
43-
<index referenceId="SEARCH_QUERY_STORE_ID" indexType="btree">
44-
<column name="store_id"/>
45-
</index>
4643
<index referenceId="SEARCH_QUERY_IS_PROCESSED" indexType="btree">
4744
<column name="is_processed"/>
4845
</index>
49-
<index referenceId="SEARCH_QUERY_STORE_ID_POPULARITY" indexType="btree">
46+
<index referenceId="SEARCH_QUERY_STORE_ID_NUM_RESULTS_POPULARITY" indexType="btree">
5047
<column name="store_id"/>
48+
<column name="num_results"/>
5149
<column name="popularity"/>
5250
</index>
51+
<index referenceId="SEARCH_QUERY_STORE_ID_POPULARITY" indexType="btree" disabled="true">
52+
<column name="store_id"/>
53+
<column name="popularity"/>
54+
</index>
55+
<index referenceId="SEARCH_QUERY_STORE_ID" indexType="btree" disabled="true">
56+
<column name="store_id"/>
57+
</index>
5358
</table>
5459
<table name="search_synonyms" resource="default" engine="innodb" comment="table storing various synonyms groups">
5560
<column xsi:type="bigint" name="group_id" unsigned="true" nullable="false" identity="true"

app/code/Magento/Search/etc/db_schema_whitelist.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
},
1616
"index": {
1717
"SEARCH_QUERY_QUERY_TEXT_STORE_ID_POPULARITY": true,
18-
"SEARCH_QUERY_STORE_ID": true,
1918
"SEARCH_QUERY_IS_PROCESSED": true,
2019
"SEARCH_QUERY_SYNONYM_FOR": true,
21-
"SEARCH_QUERY_STORE_ID_POPULARITY": true
20+
"SEARCH_QUERY_STORE_ID_NUM_RESULTS_POPULARITY": true,
21+
"SEARCH_QUERY_STORE_ID": false,
22+
"SEARCH_QUERY_STORE_ID_POPULARITY": false
2223
},
2324
"constraint": {
2425
"PRIMARY": true,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Search\Model\ResourceModel\Query;
9+
10+
use Magento\Search\Model\ResourceModel\Query;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
use Magento\Framework\DB\Adapter\Pdo\Mysql;
15+
16+
class CollectionTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* @var Query
20+
*/
21+
private $queryResource;
22+
23+
/**
24+
* @inheritDoc
25+
*/
26+
protected function setUp(): void
27+
{
28+
$objectManager = Bootstrap::getObjectManager();
29+
$this->queryResource = $objectManager->get(Query::class);
30+
}
31+
32+
public function testSearchQueryTableHasProperIndex()
33+
{
34+
$table = $this->queryResource->getTable('search_query');
35+
$indexName = 'SEARCH_QUERY_STORE_ID_NUM_RESULTS_POPULARITY';
36+
$connection = $this->queryResource->getConnection();
37+
$tableIndexes = $connection->getIndexList($table);
38+
$this->assertArrayHasKey($indexName, $tableIndexes);
39+
}
40+
}

0 commit comments

Comments
 (0)