-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
// See https://stackoverflow.com/a/25489055/9959073 for details. | ||
jQuery.ajaxSetup({async:false}); | ||
|
||
/* Non-minified version JS is _stemmer.js if file is provided */ | ||
/* Non-minified version JS is _stemmer.js if file is provided */ | ||
/** | ||
* Porter Stemmer | ||
*/ | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This should be just |
||
|
||
for(var i = 0; i < docResultsCount; i++ ) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The link now includes the extension. |
||
'?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 commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
'<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 commentThe reason will be displayed to describe this comment to others. Learn more. This should be iterating over |
||
docResponse.results.hits.hits[i].highlight.content[1] + | ||
'</div> </li>'; | ||
|
@@ -563,7 +563,7 @@ var Search = { | |
if (item[3]) { | ||
listItem.append($('<span> (' + item[3] + ')</span>')); | ||
Search.output.append(listItem); | ||
|
||
listItem.slideDown(5, function() { | ||
displayNextItem(); | ||
}); | ||
|
@@ -590,7 +590,7 @@ var Search = { | |
listItem.slideDown(5, function() { | ||
displayNextItem(); | ||
}); | ||
} | ||
} | ||
} | ||
// search finished, update title and status message | ||
else { | ||
|
@@ -775,19 +775,19 @@ var Search = { | |
*/ | ||
makeSearchSummary : function(text, keywords, hlwords) { | ||
var textLower = text.toLowerCase(); | ||
|
||
//extracting an image for the thumbnail | ||
var imageSearch = textLower.indexOf('nboutput',0); | ||
var imageTypeJPEG = textLower.indexOf('.jpeg', imageSearch); | ||
var imageTypePNG = textLower.indexOf('.png', imageSearch); | ||
var imageTypeJPG = textLower.indexOf('.jpg', imageSearch); | ||
imageType = ( (imageTypeJPEG == -1) || ((imageTypeJPG != -1) && (imageTypeJPG < imageTypeJPEG)) )? imageTypeJPG : imageTypeJPEG ; | ||
imageType = ( (imageTypeJPEG == -1) || ((imageTypeJPG != -1) && (imageTypeJPG < imageTypeJPEG)) )? imageTypeJPG : imageTypeJPEG ; | ||
imageURLEnd = ( (imageType == -1) || ((imageTypePNG != -1) && (imageTypePNG < imageType)) )? imageTypePNG : imageType ; //to end the URL with appropriate extention | ||
var imageURL = $.trim(text.substr((imageSearch+8),(imageURLEnd-imageSearch))) | ||
if(imageURL == "" || imageURL.length > 80) //to add default image | ||
{imageURL = "_static/default_thumbnail.png";} | ||
else | ||
{imageURL = '_images' + imageURL;} | ||
{imageURL = '_images' + imageURL;} | ||
|
||
//extracting context | ||
textLower = textLower.replace(/<[^<>]*>/gi, ''); //removing the html tags | ||
|
@@ -810,12 +810,12 @@ var Search = { | |
else{ | ||
var startPoint = textLower.indexOf('====',0); | ||
var start = startPoint; | ||
var sentenceStart = 0; | ||
var sentenceStart = 0; | ||
$.each(keywords, function() { | ||
var finderStart = startPoint; | ||
var flag = 0; | ||
var firstFound =-1; | ||
|
||
while(flag==0 && sentenceStart!=80){ | ||
var i = textLower.indexOf(this.toLowerCase(),finderStart); | ||
if (i > -1) | ||
|
@@ -825,8 +825,8 @@ var Search = { | |
sentenceStart=0; | ||
flag =1; | ||
break;} | ||
for( sentenceStart = 0; sentenceStart<80; sentenceStart++){ | ||
|
||
for( sentenceStart = 0; sentenceStart<80; sentenceStart++){ | ||
if((textLower.charAt(start - sentenceStart) == '>') || (textLower.charAt(start - sentenceStart) == '<')) { | ||
finderStart = start+1; | ||
if(finderStart == startPoint) | ||
|
@@ -845,14 +845,14 @@ var Search = { | |
|
||
var excerpt = trimmedText.replace(/[`~!@#$%^&*()_|+\-=?:'"<>\{\}\[\]\\\/]/gi, ''); | ||
excerpt = '<div class="row"><div class="col-md-3"><img src="' + imageURL + '" style="width: 150px; padding-top: 5px;"></div> <div class="col-md-9" style="padding-top: 20px; padding-left: 0px;">' + excerpt + '</div></div></div>' | ||
|
||
var rv = $('<div class="context"></div>').html(excerpt); | ||
$.each(hlwords, function() { | ||
if(this.search('filter')==-1){ //if "filter" is not there in the search query then directly use the query to highlight text | ||
rv = rv.highlightText(this, 'highlighted'); | ||
} else { //if "filter" is there in the search query then first strip "filter" from the query and then use it to highlight text | ||
rv = rv.highlightText(this.split('filter')[1], 'highlighted'); | ||
} | ||
} | ||
}); | ||
return rv; | ||
} | ||
|
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:
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
:/
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.
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.
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.
@adrn , @eblur , or @kelle , do you remember why this decision was made? Can you please help @embray move this forward? Thanks.
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.
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.