From 4c67f595d7f7ae34883b71e8141fdcc9f7f8b76a Mon Sep 17 00:00:00 2001 From: atqy <95724753+atqy@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:49:20 -0700 Subject: [PATCH] Add RTD Search Filters (#3581) * add filters * correct search url * change search textbox * change search box text * remove AWS in AWS Dev Guide * cleanup * more cleanup --- _static/kendrasearchtools.js | 24 ++++++++++++++++-------- _templates/searchbox.html | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 _templates/searchbox.html diff --git a/_static/kendrasearchtools.js b/_static/kendrasearchtools.js index f2d47ef889..4920607010 100644 --- a/_static/kendrasearchtools.js +++ b/_static/kendrasearchtools.js @@ -533,11 +533,19 @@ var KendraSearch = { _pulse_status : -1, init : function() { + var filters = {}; var params = $.getQueryParameters(); if (params.q) { var query = params.q[0]; $('input[name="q"]')[0].value = query; - this.performSearch(query); + + Object.keys(params).forEach(function(key) { + if(key.startsWith("filter")){ + filters[key] = true; + $('input[name="' + key + '"]')[0].checked = true; + } + }); + this.performSearch(query, filters=filters); } }, @@ -577,8 +585,8 @@ var KendraSearch = { /** * execute search (requires search index to be loaded) */ - query : function(query, pageNumber, pageSize=10) { - var url = " https://9cs56celvj.execute-api.us-west-2.amazonaws.com/prod" + query : function(query, pageNumber, pageSize=10, filters={}) { + var url = "https://9cs56celvj.execute-api.us-west-2.amazonaws.com/prod" $('#search-progress').empty(); @@ -586,7 +594,7 @@ var KendraSearch = { fetch(url, { method: 'post', - body: JSON.stringify({ "queryText": query , "pageNumber": pageNumber, "pageSize": pageSize, "host": window.location.host}), + body: JSON.stringify({ "queryText": query , "pageNumber": pageNumber, "pageSize": pageSize, "filters": filters, "host": window.location.host}), }).then(response => response.json()) .then(function(data) { var docs = data["ResultItems"]; @@ -602,7 +610,7 @@ var KendraSearch = { if(doc_url.includes("sagemaker-examples.readthedocs.io")){ type_badge_html = 'Example' }else if(doc_url.includes("docs.aws.amazon.com")){ - type_badge_html = 'AWS Dev Guide' + type_badge_html = 'Dev Guide' }else if(doc_url.includes("sagemaker.readthedocs.io") || doc_url.includes("sagemaker-debugger.readthedocs.io")){ type_badge_html = 'SDK Guide' } @@ -656,7 +664,7 @@ var KendraSearch = { $(element).on('click', function() { KendraSearch.output.empty(); paginationItem.remove(); - KendraSearch.query(query, parseInt($(element).attr('id').split("-")[1])); + KendraSearch.query(query, parseInt($(element).attr('id').split("-")[1]), pageSize, filters); }); }); } @@ -670,7 +678,7 @@ var KendraSearch = { /** * perform a search for something (or wait until index is loaded) */ - performSearch : function(query) { + performSearch : function(query, filters) { // create the required interface elements this.out = $('#search-results'); this.title = $('

' + _('Searching...') + '

').appendTo(this.out); @@ -682,7 +690,7 @@ var KendraSearch = { $('#search-progress').text(_('Preparing search...')); this.startPulse(); - this.query(query, 1) + this.query(query, 1, pageSize=10, filters=filters) }, }; diff --git a/_templates/searchbox.html b/_templates/searchbox.html new file mode 100644 index 0000000000..a7c5aeb1d8 --- /dev/null +++ b/_templates/searchbox.html @@ -0,0 +1,14 @@ +
+
+ +
+
+
+
Filters:
+
+
+
+
+ +
+
\ No newline at end of file