diff options
Diffstat (limited to 'doc/html/_static/searchtools.js')
-rw-r--r-- | doc/html/_static/searchtools.js | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/doc/html/_static/searchtools.js b/doc/html/_static/searchtools.js index 5ff3180..970d0d9 100644 --- a/doc/html/_static/searchtools.js +++ b/doc/html/_static/searchtools.js @@ -4,7 +4,7 @@ * * Sphinx JavaScript utilities for the full-text search. * - * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -36,8 +36,10 @@ if (!Scorer) { // query found in title title: 15, + partialTitle: 7, // query found in terms - term: 5 + term: 5, + partialTerm: 2 }; } @@ -56,6 +58,19 @@ var Search = { _queued_query : null, _pulse_status : -1, + htmlToText : function(htmlString) { + var htmlElement = document.createElement('span'); + htmlElement.innerHTML = htmlString; + $(htmlElement).find('.headerlink').remove(); + docContent = $(htmlElement).find('[role=main]')[0]; + if(docContent === undefined) { + console.warn("Content block not found. Sphinx search tries to obtain it " + + "via '[role=main]'. Could you check your theme or template."); + return ""; + } + return docContent.textContent || docContent.innerText; + }, + init : function() { var params = $.getQueryParameters(); if (params.q) { @@ -120,7 +135,7 @@ var Search = { this.out = $('#search-results'); this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out); this.dots = $('<span></span>').appendTo(this.title); - this.status = $('<p style="display: none"></p>').appendTo(this.out); + this.status = $('<p class="search-summary"> </p>').appendTo(this.out); this.output = $('<ul class="search"/>').appendTo(this.out); $('#search-progress').text(_('Preparing search...')); @@ -151,8 +166,7 @@ var Search = { objectterms.push(tmp[i].toLowerCase()); } - if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i].match(/^\d+$/) || - tmp[i] === "") { + if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i] === "") { // skip this "word" continue; } @@ -235,7 +249,9 @@ var Search = { if (results.length) { var item = results.pop(); var listItem = $('<li style="display:none"></li>'); - if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') { + var requestUrl = ""; + var linkUrl = ""; + if (DOCUMENTATION_OPTIONS.BUILDER === 'dirhtml') { // dirhtml builder var dirname = item[0] + '/'; if (dirname.match(/\/index\/$/)) { @@ -243,15 +259,17 @@ var Search = { } else if (dirname == 'index/') { dirname = ''; } - listItem.append($('<a/>').attr('href', - DOCUMENTATION_OPTIONS.URL_ROOT + dirname + - highlightstring + item[2]).html(item[1])); + requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname; + linkUrl = requestUrl; + } else { // normal html builders - listItem.append($('<a/>').attr('href', - item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX + - highlightstring + item[2]).html(item[1])); + requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX; + linkUrl = item[0] + DOCUMENTATION_OPTIONS.LINK_SUFFIX; } + listItem.append($('<a/>').attr('href', + linkUrl + + highlightstring + item[2]).html(item[1])); if (item[3]) { listItem.append($('<span> (' + item[3] + ')</span>')); Search.output.append(listItem); @@ -259,11 +277,7 @@ var Search = { displayNextItem(); }); } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) { - var suffix = DOCUMENTATION_OPTIONS.SOURCELINK_SUFFIX; - if (suffix === undefined) { - suffix = '.txt'; - } - $.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[5] + (item[5].slice(-suffix.length) === suffix ? '' : suffix), + $.ajax({url: requestUrl, dataType: "text", complete: function(jqxhr, textstatus) { var data = jqxhr.responseText; @@ -313,12 +327,13 @@ var Search = { for (var prefix in objects) { for (var name in objects[prefix]) { var fullname = (prefix ? prefix + '.' : '') + name; - if (fullname.toLowerCase().indexOf(object) > -1) { + var fullnameLower = fullname.toLowerCase() + if (fullnameLower.indexOf(object) > -1) { var score = 0; - var parts = fullname.split('.'); + var parts = fullnameLower.split('.'); // check for different match types: exact matches of full name or // "last name" (i.e. last dotted part) - if (fullname == object || parts[parts.length - 1] == object) { + if (fullnameLower == object || parts[parts.length - 1] == object) { score += Scorer.objNameMatch; // matches in last name } else if (parts[parts.length - 1].indexOf(object) > -1) { @@ -385,6 +400,19 @@ var Search = { {files: terms[word], score: Scorer.term}, {files: titleterms[word], score: Scorer.title} ]; + // add support for partial matches + if (word.length > 2) { + for (var w in terms) { + if (w.match(word) && !terms[word]) { + _o.push({files: terms[w], score: Scorer.partialTerm}) + } + } + for (var w in titleterms) { + if (w.match(word) && !titleterms[word]) { + _o.push({files: titleterms[w], score: Scorer.partialTitle}) + } + } + } // no match but word was a required one if ($u.every(_o, function(o){return o.files === undefined;})) { @@ -404,7 +432,7 @@ var Search = { for (j = 0; j < _files.length; j++) { file = _files[j]; if (!(file in scoreMap)) - scoreMap[file] = {} + scoreMap[file] = {}; scoreMap[file][word] = o.score; } }); @@ -412,7 +440,7 @@ var Search = { // create the mapping for (j = 0; j < files.length; j++) { file = files[j]; - if (file in fileMap) + if (file in fileMap && fileMap[file].indexOf(word) === -1) fileMap[file].push(word); else fileMap[file] = [word]; @@ -424,8 +452,12 @@ var Search = { var valid = true; // check if all requirements are matched - if (fileMap[file].length != searchterms.length) - continue; + var filteredTermCount = // as search terms with length < 3 are discarded: ignore + searchterms.filter(function(term){return term.length > 2}).length + if ( + fileMap[file].length != searchterms.length && + fileMap[file].length != filteredTermCount + ) continue; // ensure that none of the excluded terms is in the search result for (i = 0; i < excluded.length; i++) { @@ -456,7 +488,8 @@ var Search = { * words. the first one is used to find the occurrence, the * latter for highlighting it. */ - makeSearchSummary : function(text, keywords, hlwords) { + makeSearchSummary : function(htmlText, keywords, hlwords) { + var text = Search.htmlToText(htmlText); var textLower = text.toLowerCase(); var start = 0; $.each(keywords, function() { |