diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css index fd48b99c149..2a39f1f3383 100644 --- a/docs/_static/css/custom.css +++ b/docs/_static/css/custom.css @@ -115,3 +115,8 @@ div.highlight { max-width: 1800px; } } + +main .searchForm { + margin-bottom: 2rem; + margin-top: 2rem; +} diff --git a/docs/_static/css/gsearch.css b/docs/_static/css/gsearch.css new file mode 100644 index 00000000000..ebd160a9fea --- /dev/null +++ b/docs/_static/css/gsearch.css @@ -0,0 +1,98 @@ +/* Google Search */ + +div.gs-result { + padding: 15px 0px; +} + +div.gs-result::after { + clear: both; + content: ""; + display: block; + } + +div.gs-title > a { + color: #2171b8; + font-size: 18px; +} + +div.gs-title > a:visited { + color: #609; +} + +div.gs-url { + font-size: 12px; + color: #1E9F40; +} + +div.gs-cursor { + margin-top: 40px; + cursor: pointer; +} + +a.gs-cursor-page { + margin-right: 10px; +} + +a.gs-cursor-page-previous { + margin-right: 30px; +} + +a.gs-cursor-page-next { + margin-left: 30px; +} + +div.gs-cursor a.active { + color: #2171b8; + font-weight: bold; +} + +div.gs-media { + float: left; + margin-right: 4px; +} + +div.gs-media img { + max-width: 60px; + max-height: 120px; +} + +div.gs-file-format-box { + font-size: 12px; +} + +span.gs-file-format { + color: #6e6e6e; +} + +div.gs-file-type { + font-weight: bold; +} + +div.gs-no-results { + border: 1px solid rgb(255,204,51); + background-color: rgb(255,244,194); + color: black; +} + +/* Version tabs */ + +#gs-tabs-area { + margin-top:2rem; +} + +a.gs-tab { + display: inline-block; + padding: 0px 10px; + margin-bottom: 1px; + text-transform: uppercase; + cursor: pointer; +} + +a.gs-tab-active { + border-bottom: 2px solid #2171b8; + pointer-events: none; + cursor: default; + text-decoration: none; + color: #2171b8 !important; + font-weight: bold; +} diff --git a/docs/_static/js/custom.js b/docs/_static/js/custom.js index 8e323f6fa6e..7ef541f26f6 100644 --- a/docs/_static/js/custom.js +++ b/docs/_static/js/custom.js @@ -45,6 +45,7 @@ $(document).ready(function () { addTableSort(); } addLegalNotice(); + updateSearchForm(); createSphinxTabSets(); }); @@ -108,6 +109,10 @@ function getCurrentVersion() { return encodeURI(wordAfterDomain); } +function updateSearchForm() { + var currentVersion = getCurrentVersion(); + $('.searchForm').append(''); +} function createVersions() { var currentVersion = getCurrentVersion(); diff --git a/docs/_static/js/gsearch.js b/docs/_static/js/gsearch.js new file mode 100644 index 00000000000..122fd92dd3c --- /dev/null +++ b/docs/_static/js/gsearch.js @@ -0,0 +1,376 @@ +/* API config */ +var cx = '012886673101693426607:wjpczzz2qi3'; +var path = 'https://content.googleapis.com/discovery/v1/apis/customsearch/v1/rest'; +var apiKey = 'AIzaSyBpwSxfoP2T_EK62wwNhZ9zyxUzeRjmOwA'; + + +var potKeywords = ['int8', '8-bit', '8 bit', 'quantization', 'quantized', + 'quantizer', 'fakequantize', 'fq', 'model optimization', + 'low precision', 'low-precision', 'lower precision', 'pot', + 'compression', 'calibration', 'post-training', 'post training']; + +// get the docs versions stored in versions_raw.js +var versions; +try { + versions = JSON.parse(data); +} +catch(e) { + versions = []; +}; + +function hasPotTerms(query) { + q = query.toLowerCase(); + return potKeywords.some(function(k) { + k = k.toLowerCase(); + return q.indexOf(k) != -1; + }); +} + +function boostPage(name, pages, pos) { + var tmp; + pages = pages || []; + for (var i = 1; i < pages.length; i++) { + if (name === getPageName(pages[i].link)) { + tmp = pages[pos]; + pages[pos] = pages[i]; + pages[i] = tmp; + pos++; + } + } +} + +function getPageName(url) { + urlArr = url.split('/'); + return urlArr[urlArr.length - 1]; +} + +function getURLParameter(name) { + return decodeURIComponent((new RegExp('[?|&]'+name+ + '='+'([^&;]+?)(&|#|;|$)').exec(location.search) + ||[,""])[1].replace(/\+/g, '%20'))||null; +} + +function search(query, selectedVersion, page, key) { + // make a query to Google Search API and render the results + var start = getStartIndex(page); // get start index from page number + var documentationHost = 'https://docs.openvino.ai'; + if (selectedVersion === 'ALL') { + var siteSearch = documentationHost; + } + else { + var siteSearch = documentationHost + '/' + selectedVersion; + } + var path = 'https://www.googleapis.com/customsearch/v1?cx=' + cx + '&q=' + query + '&siteSearch=' + siteSearch + '&start=' + start; + var hasPot = hasPotTerms(query); + if (hasPot) { + path += '&qt="pot"'; + } + + return async function() { + await gapi.client.init({ + 'apiKey': apiKey, + }).then(function() { + return gapi.client.request({ + 'path': path + }) + }).then(function(response) { + handleResponse(response, selectedVersion, hasPot); + }, function(err) { + console.log(err); + handleNoResults(); + }); + } +} + +function getPageNum(index) { + // get page number from page index + return Math.floor((index-1) / 10) + 1; +} + +function getStartIndex(page) { + // get start index from page number + return (page - 1) * 10 + 1; +} + +function handleNoResults() { + var $noResults = $('
+ Search Results... +
+ + {% block scriptwarning %} +