Skip to content

Commit 6e82722

Browse files
committed
MAGETWO-75769: Cache Popular Search Terms and Their Search Results Pages
1 parent 47c55ae commit 6e82722

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

app/code/Magento/CatalogSearch/view/frontend/templates/search_terms_log.phtml

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
?>
88
<?php if ($block->getSearchTermsLog()->isPageCacheable()): ?>
99
<script type="text/x-magento-init">
10-
<?= /* @escapeNotVerified */ json_encode([
11-
'*' => [
12-
'Magento_CatalogSearch/js/search_terms_log' => [
13-
'url' => $block->getUrl('catalogsearch/searchTermsLog/save')
14-
]
15-
]
16-
]); ?>
10+
{
11+
"*": {
12+
"Magento_CatalogSearch/js/search-terms-log": {
13+
"url": "<?= /* @escapeNotVerified */ $block->getUrl('catalogsearch/searchTermsLog/save') ?>"
14+
}
15+
}
16+
}
1717
</script>
1818
<?php endif; ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery'
8+
], function ($) {
9+
'use strict';
10+
11+
/**
12+
* Return url parameters.
13+
* @returns {Object}
14+
*/
15+
function urlParameters() {
16+
var params = {}, queries, temp, i, l,
17+
queryString = window.location.search;
18+
19+
queryString = queryString.substring(1);
20+
queries = queryString.split("&");
21+
for ( i = 0, l = queries.length; i < l; i++ ) {
22+
temp = queries[i].split('=');
23+
params[temp[0]] = temp[1];
24+
}
25+
26+
return params;
27+
}
28+
29+
return function (data) {
30+
var url = data.url;
31+
32+
$.ajax({
33+
method: 'GET',
34+
url: url,
35+
data: {
36+
'q': urlParameters()['q']
37+
},
38+
cache: false
39+
});
40+
};
41+
});

app/code/Magento/CatalogSearch/view/frontend/web/js/search_terms_log.js

-34
This file was deleted.

dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/ResultTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testPopularSearch()
104104

105105
$responseBody = $this->getResponse()->getBody();
106106
$this->assertContains('Search results for: &#039;popular_query_text&#039;', $responseBody);
107-
$this->assertContains('\/catalogsearch\/searchTermsLog\/save\/', $responseBody);
107+
$this->assertContains('/catalogsearch/searchTermsLog/save/', $responseBody);
108108

109109
$query->loadByQueryText('popular_query_text');
110110
$this->assertEquals(100, $query->getPopularity());
@@ -128,7 +128,7 @@ public function testPopularSearchWithAdditionalRequestParameters()
128128

129129
$responseBody = $this->getResponse()->getBody();
130130
$this->assertContains('Search results for: &#039;popular_query_text&#039;', $responseBody);
131-
$this->assertNotContains('\/catalogsearch\/searchTermsLog\/save\/', $responseBody);
131+
$this->assertNotContains('/catalogsearch/searchTermsLog/save/', $responseBody);
132132

133133
$query->loadByQueryText('popular_query_text');
134134
$this->assertEquals(101, $query->getPopularity());
@@ -152,7 +152,7 @@ public function testNotPopularSearch()
152152

153153
$responseBody = $this->getResponse()->getBody();
154154
$this->assertContains('Search results for: &#039;query_text&#039;', $responseBody);
155-
$this->assertNotContains('\/catalogsearch\/searchTermsLog\/save\/', $responseBody);
155+
$this->assertNotContains('/catalogsearch/searchTermsLog/save/', $responseBody);
156156

157157
$query->loadByQueryText('query_text');
158158
$this->assertEquals(2, $query->getPopularity());

0 commit comments

Comments
 (0)