-
Notifications
You must be signed in to change notification settings - Fork 181
MNT: Use new RTD search API #462
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
Conversation
Looping in @jonathansick , this sounds like something he may have thoughts on. |
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.
The response of the API changed, you can take a look at the new response in https://docs.astropy.org/_/api/v2/search/?q=test&project=astropy&version=stable or check the docs at https://docs.readthedocs.io/en/stable/server-side-search.html#api
@@ -416,17 +416,17 @@ var Search = { | |||
if (query.includes("filterTutorials")) { // don't search docs if we are just looking for tutorials | |||
var docResponse = null; | |||
var docResult = ''; | |||
$.get('https://readthedocs.org/api/v2/docsearch/?q=' + window.location.search.split('=')[1] + '&project=astropy&version=stable&language=en', function(response){ | |||
$.get('https://docs.readthedocs.io/_/api/v2/search/?q=' + window.location.search.split('=')[1] + '&project=astropy&version=stable', function(response){ | |||
docResponse = response; | |||
//limits the maximum results from the documentation to 15 | |||
docResultsCount = (docResponse.results.hits.total>15)? 15 : docResponse.results.hits.total ; |
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.
This should be just results.length
@@ -416,17 +416,17 @@ var Search = { | |||
if (query.includes("filterTutorials")) { // don't search docs if we are just looking for tutorials | |||
var docResponse = null; | |||
var docResult = ''; | |||
$.get('https://readthedocs.org/api/v2/docsearch/?q=' + window.location.search.split('=')[1] + '&project=astropy&version=stable&language=en', function(response){ | |||
$.get('https://docs.readthedocs.io/_/api/v2/search/?q=' + window.location.search.split('=')[1] + '&project=astropy&version=stable', function(response){ |
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.
The new endpoint should be https://docs.astropy.org/_/api/v2/search/?q=test&project=astropy&version=stable
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.
When I try to make this query from learn.astropy.org I get CORS errors:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://docs.astropy.org/_/api/v2/search/?q=test&project=astropy&version=stable. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Is this related to readthedocs/readthedocs.org#6154 ? Is there any hope of working around this?
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.
oh, I think you can use the other endpoint https://readthedocs.org/api/v2/search/?q=test&project=astropy&version=stable let me know if that one works
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 still get
Access to XMLHttpRequest at 'https://readthedocs.org/api/v2/search/?q=test&project=astropy&version=stable' from origin 'http://learn.astropy.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
:/
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.
hmm, not sure how this was working before.
Looks like you can get around by creating a custom domain with "learn.astropy.org", there is no need to add the CNAME, this is so rtd knows this is a known domain.
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.
Oh, I found the settings on RTD for adding an additional custom domain. I see your point now about adding it as a custom domain without actually adding a CNAME entry. Hopefully that should work (it does not yet, but it still shows "SSL certificate status: pending_validation" on https://readthedocs.org/dashboard/astropy/domains/10700/edit/
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.
It appears to be due to this, but in this case RTD wouldn't be issuing an SSL cert on behalf of the site: https://docs.readthedocs.io/en/stable/custom_domains.html#certificate-authority-authorization
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.
Although looking again at the code you linked, for the CORS access it doesn't seem to care about certificate status :/
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 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.
Although looking again at the code you linked, for the CORS access it doesn't seem to care about certificate status
Yeah, you only need to add the domain, the status or the CNAME don't matter here. Let me know if that fixed the CORS problem.
docResult += '<li style="" class="result-card doc"> <a href="' + | ||
docResponse.results.hits.hits[i].fields.link + '.html' + | ||
docResult += '<li style="" class="result-card doc"> <a href="' + | ||
docResponse.results.hits.hits[i].fields.link + '.html' + |
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.
The link now includes the extension. results[i].domain + results[i].path
docResult += '<li style="" class="result-card doc"> <a href="' + | ||
docResponse.results.hits.hits[i].fields.link + '.html' + | ||
docResult += '<li style="" class="result-card doc"> <a href="' + | ||
docResponse.results.hits.hits[i].fields.link + '.html' + | ||
'?highlight=' + window.location.search.split('=')[1] + '">' + | ||
docResponse.results.hits.hits[i].fields.title[0] + '</a>' + |
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.
this should be results[i].title
'?highlight=' + window.location.search.split('=')[1] + '">' + | ||
docResponse.results.hits.hits[i].fields.title[0] + '</a>' + | ||
'<div class="context">' + | ||
'<div class="context">' + | ||
docResponse.results.hits.hits[i].highlight.content[0] + |
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.
This should be iterating over results[i].blocks
Thanks, @stsewd ! Just want you to know that I received your much appreciated review, but don't have time to follow-up yet. |
Sorry I didn't get to work on this sooner. I guess it's more urgent than I remembered. |
I'm implementing @stsewd 's review comments. |
Go for it, @embray . I'll hold off. Thank you for your help! |
I started this but I am not really involved on the JS side of things here, so if someone else wanna take over, feel free. Fix #459
Will a simple URL search and replace be sufficient, or we need to change other stuff too?
cc @embray