-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix #4265] Porting frontend docsearch to work with new API #4340
[Fix #4265] Porting frontend docsearch to work with new API #4340
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, except for some JS style changes. I don't know JS well enough to check for anything obviously wrong there, but it looks like a pretty simple update to the JS code.
for (var i = 0; i < hit_list.length; i += 1) { | ||
var document = hit_list[i]; | ||
var highlight = document.highlight; | ||
var $list_item = $('<li style="display: none;"></li>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're doing here, but we don't follow this convention anywhere else in the code, so we shouldn't do it here to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we do not follow the convention. But it actually makes me bit much of confused while writing JS code. without knowing if its a jquery object, its hard to keep track. I am ok to have it like before, but what do you think if we should start following the convention?
list_item.append(content); | ||
|
||
// Show highlighted texts | ||
if (highlight.content) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to check length
here? I don't know JS well enough, but that's what we were doing before, so probably worth keeping it explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous API, the content
was provided as a blank list if there are no match in content. but our current API do not provide anything in the content
key if there are not anything in the content. So checking the length may raise error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. I think we can eventually update this interface, but +1 on keeping the logic the same for now.
I've noted some cleanup issues to the javascript, there are some deviations from our current style patterns.
$('<span>') | ||
.text(" (from project " + fields.project + ")") | ||
); | ||
for (var i = 0; i < hit_list.length; i += 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (var n in hit_list)
is a more readable iteration format and is support down to ie6
for (var i = 0; i < hit_list.length; i += 1) { | ||
var doc = hit_list[i]; | ||
var highlight = doc.highlight; | ||
var $list_item = $('<li style="display: none;"></li>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, we don't prefix vars with $
var link = doc.link + DOCUMENTATION_OPTIONS.FILE_SUFFIX + | ||
'?highlight=' + $.urlencode(query); | ||
|
||
var $item = $('<a>', {'href': link}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same $
prefix
$list_item.append($item); | ||
|
||
// If the document is from subproject, add extra information | ||
if (doc.project !== project) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful that this doesn't revert to buggy behavior, if the return attributedoc.proejct
hasn't changed. The equivalent of doc.project
in the current js is always an array, so doc.project !== project
is false because doc.project = ['docs']
and project = 'docs'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed over slack, the new API always return String
, instead of list.
// If the document is from subproject, add extra information | ||
if (doc.project !== project) { | ||
var text = " (from project " + doc.project + ")"; | ||
var $extra = $('<span>', {'text': text}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more $
prefix
// Show highlighted texts | ||
if (highlight.content) { | ||
var content_text = xss(highlight.content[0]); | ||
var $contents = $('<div class="context">'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More $
prefix
@@ -96,11 +96,11 @@ function attach_elastic_search_query(data) { | |||
withCredentials: true, | |||
}, | |||
complete: function (resp, status_code) { | |||
if (typeof (resp.responseJSON) === 'undefined' || | |||
typeof (resp.responseJSON.results) === 'undefined') { | |||
console.log(status_code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug logging can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of conflicts to testing this locally (notably a conflicting migration on projects/0026
). Would it be possible to sync up to master?
👍 on resyncing the |
@davidfischer Yes. there are lot of conflicts as the branch is old. Can you cherry pick your asset generation commits to the branch and generate assets to test? @ericholscher I am hoping to rebase the |
@agjohnson I have fixed the issue as you have mentioned. r? |
@ericholscher possible to merge? |
[Fix readthedocs#4265] Porting frontend docsearch to work with new API
[Fix readthedocs#4265] Porting frontend docsearch to work with new API
This fixes #4265
I have ported the existing search javascript in order to work with the new Restful search API. The API has been implemented in #4309.
@ericholscher @davidfischer r?