1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00

Merge pull request #18644 from openshift-cherrypick-robot/cherry-pick-18642-to-enterprise-4.3

[enterprise-4.3] search: fix pagination
This commit is contained in:
Vikram Goyal
2019-12-16 10:50:25 +10:00
committed by GitHub
2 changed files with 2 additions and 55 deletions

View File

@@ -54,7 +54,7 @@ function hcsearch(searchParams) {
var searchprovider = "https://search.help.openshift.com/json";
var searchReq = { "q" : searchParams.q + searchParams.urlFilter,
"fields.label" : searchParams.label,
"si" : searchParams.si } // q = query, l = label
"start" : searchParams.si }
hcMoreBtn.hide();
hcSearchIndicator.show();

View File

@@ -180,6 +180,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
</div>
</footer>
<script src="https://docs.openshift.com/container-platform/4.1/_javascripts/hc-search.js" type="text/javascript"></script>
<script type="text/javascript">
// custom help.openshift.com search
function parseParamsFromUrl() {
@@ -193,60 +194,6 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
return params;
} // function parseParamsFromUrl()
function hcsearch(searchParams) {
// elements used repeatedly
var hcMoreBtn = $("#hc-search-more-btn");
var hcSearchIndicator = $("#hc-search-progress-indicator");
var hcSearchResult = $("#hc-search-results");
// the "searchprovider" is to return a JSON response in the expected format
var searchprovider = "https://search.help.openshift.com/json";
var searchReq = { "q" : searchParams.q + searchParams.urlFilter,
"fields.label" : searchParams.label,
"si" : searchParams.si } // q = query, l = label
hcMoreBtn.hide();
hcSearchIndicator.show();
$.get(searchprovider, searchReq).done(function (hcsearchresults) {
// GET success
if (hcsearchresults == "") {
// success, but no response (response code mismatch)
$("#hc-search-result").append("<p><strong>An error occured while retrieving search results. Please try again later.</strong></p>");
hcSearchIndicator.hide();
}
if (hcsearchresults.response.result) {
// if there are any results
$(hcsearchresults.response.result).each(function () {
var row = '<div class="search-result-item"><a href="' + this.url +
'" target="_blank">' + this.title + '</a>';
row += '<p class="excerpt">' + this.content_description.replace(/\<br\>/g, ' ') + '</p></div>';
hcSearchResult.append(row);
});
if (hcsearchresults.response.page_number < hcsearchresults.response.page_count) {
// if there are more results beyond the retrieved ones
// index of the first item on the next page (first item = 0, first page = 1)
searchParams.si = hcsearchresults.response.page_number * hcsearchresults.response.page_size;
// replace any existing click handler with one to fetch the next set of results
hcMoreBtn.off('click');
hcMoreBtn.click(function() {
hcsearch(searchParams);
});
hcMoreBtn.show();
} else {
// no more results beyond the retrieved ones
hcSearchResult.append("<p><strong>No more results.</strong></p>");
}
} else {
if (searchParams.si > 0) {
// no results reurned, but some already displayed
hcSearchResult.append("<p><strong>No more results.</strong></p>");
} else {
// no results on initial search
hcSearchResult.append("<p><strong>No results found. Try rewording your search.</strong></p>");
}
return params;
}
var urlParams = parseParamsFromUrl();
var queryParamName = 'query';
var searchLabel = 'docs';