Skip to content

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

Closed
wants to merge 1 commit into from
Closed

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Oct 12, 2020

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

@kelle
Copy link
Member

kelle commented Oct 12, 2020

Looping in @jonathansick , this sounds like something he may have thoughts on.

Copy link

@stsewd stsewd left a 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 ;
Copy link

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){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

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?

Copy link

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

Copy link

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.

:/

Copy link

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.

https://github.com/readthedocs/readthedocs.org/blob/12598254c86e954f19c7402395d9e402f9a2aaaa/readthedocs/core/signals.py#L33-L82

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.

Copy link

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/

Copy link

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

Copy link

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 :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone who was not me apparently made the decision at one point not to

@adrn , @eblur , or @kelle , do you remember why this decision was made? Can you please help @embray move this forward? Thanks.

Copy link

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' +
Copy link

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>' +
Copy link

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] +
Copy link

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

@pllim
Copy link
Contributor Author

pllim commented Oct 14, 2020

Thanks, @stsewd ! Just want you to know that I received your much appreciated review, but don't have time to follow-up yet.

@embray
Copy link

embray commented Oct 14, 2020

Sorry I didn't get to work on this sooner. I guess it's more urgent than I remembered.

@embray
Copy link

embray commented Oct 14, 2020

I'm implementing @stsewd 's review comments.

@pllim
Copy link
Contributor Author

pllim commented Oct 14, 2020

Go for it, @embray . I'll hold off. Thank you for your help!

@adrn
Copy link
Contributor

adrn commented Sep 27, 2021

Only ~a year late, but new front-end is launching imminently, so closing this. Thanks @pllim and @stsewd, and sorry for losing track of this...

@adrn adrn closed this Sep 27, 2021
@pllim pllim deleted the rtd-depre-api branch September 27, 2021 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search: using deprecated API (https://readthedocs.org/api/v2/docsearch/)
5 participants