Skip to content

Commit

Permalink
Search: fix integration with latest sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Mar 3, 2022
1 parent 7cf66f6 commit d21b46f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Expand Up @@ -53,6 +53,17 @@ function attach_elastic_search_query_sphinx(data) {
search_url.search = '?q=' + $.urlencode(query) + '&project=' + project +
'&version=' + version + '&language=' + language;

/*
* Compatibility function to set a text to a Node or JQuery object.
*/
var setText = function (node, text) {
if (node.jquery) {
node.text(text);
} else {
node.innerText = text;
}
};

search_def
.then(function (data) {
var results = data.results || [];
Expand All @@ -61,7 +72,7 @@ function attach_elastic_search_query_sphinx(data) {
for (var i = 0; i < results.length; i += 1) {
var result = results[i];
var blocks = result.blocks;
var list_item = $('<li style="display: none;"></li>');
var list_item = $('<li>');

var title = result.title;
// if highlighted title is present, use that.
Expand Down Expand Up @@ -188,10 +199,14 @@ function attach_elastic_search_query_sphinx(data) {
}
}

Search.output.append(list_item);
list_item.slideDown(5);
if (Search.output.jquery) {
Search.output.append(list_item);
} else {
Search.output.appendChild(list_item.get(0));
}
}
Search.status.text(
setText(
Search.status,
_('Search finished, found %s page(s) matching the search query.').replace('%s', results.length)
);
} else {
Expand All @@ -206,8 +221,7 @@ function attach_elastic_search_query_sphinx(data) {
.always(function () {
$('#search-progress').empty();
Search.stopPulse();
Search.title.text(_('Search Results'));
Search.status.fadeIn(500);
setText(Search.title, _('Search Results'))
});

$.ajax({
Expand Down

0 comments on commit d21b46f

Please sign in to comment.