Skip to content

Commit 91e3596

Browse files
authored
Merge pull request #21823 from shuuji3/fix-no-search-result-with-keywords-with-spaces
Fix the no search result error when the keyword includes spaces.
2 parents 6109714 + 412b4ef commit 91e3596

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

static/js/search.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212

1313
window.getPaginationAnchors = (pages) => {
14-
var pageAnchors = '', searchTerm = window.location.search.split("=")[1].split("&")[0];
14+
var pageAnchors = '', searchTerm = window.location.search.split("=")[1].split("&")[0].replace(/%20/g, ' ');
1515
var currentPage = window.location.search.split("=")[2];
1616
currentPage = (!currentPage) ? 1 : currentPage.split("&")[0];
1717

@@ -33,7 +33,7 @@
3333
}
3434

3535
window.renderBingSearchResults = () => {
36-
var searchTerm = window.location.search.split("=")[1].split("&")[0],
36+
var searchTerm = window.location.search.split("=")[1].split("&")[0].replace(/%20/g,' '),
3737
page = window.location.search.split("=")[2],
3838
q = "site:kubernetes.io " + searchTerm;
3939

@@ -47,6 +47,7 @@
4747
ajaxConf.beforeSend = function(xhr){ xhr.setRequestHeader('Ocp-Apim-Subscription-Key', '51efd23677624e04b4abe921225ea7ec'); };
4848

4949
$.ajax(ajaxConf).done(function(res) {
50+
if (res.webPages == null) return; // If no result, 'webPages' is 'undefined'
5051
var paginationAnchors = window.getPaginationAnchors(Math.ceil(res.webPages.totalEstimatedMatches / 10));
5152
res.webPages.value.map(ob => { results += window.getResultMarkupString(ob); })
5253

0 commit comments

Comments
 (0)