*
* Sphinx JavaScript utilities for the full-text search.
*
- * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
// query found in title
title: 15,
- partialTitle: 7,
// query found in terms
- term: 5,
- partialTerm: 2
+ term: 5
};
}
_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) {
this.out = $('#search-results');
this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
this.dots = $('<span></span>').appendTo(this.title);
- this.status = $('<p class="search-summary"> </p>').appendTo(this.out);
+ this.status = $('<p style="display: none"></p>').appendTo(this.out);
this.output = $('<ul class="search"/>').appendTo(this.out);
$('#search-progress').text(_('Preparing search...'));
if (results.length) {
var item = results.pop();
var listItem = $('<li style="display:none"></li>');
- var requestUrl = "";
- var linkUrl = "";
- if (DOCUMENTATION_OPTIONS.BUILDER === 'dirhtml') {
+ if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
// dirhtml builder
var dirname = item[0] + '/';
if (dirname.match(/\/index\/$/)) {
} else if (dirname == 'index/') {
dirname = '';
}
- requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname;
- linkUrl = requestUrl;
-
+ listItem.append($('<a/>').attr('href',
+ DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
+ highlightstring + item[2]).html(item[1]));
} else {
// normal html builders
- requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
- linkUrl = item[0] + DOCUMENTATION_OPTIONS.LINK_SUFFIX;
- }
- listItem.append($('<a/>').attr('href',
- linkUrl +
+ listItem.append($('<a/>').attr('href',
+ item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
highlightstring + item[2]).html(item[1]));
+ }
if (item[3]) {
listItem.append($('<span> (' + item[3] + ')</span>'));
Search.output.append(listItem);
displayNextItem();
});
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
- $.ajax({url: requestUrl,
+ 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),
dataType: "text",
complete: function(jqxhr, textstatus) {
var data = jqxhr.responseText;
for (var prefix in objects) {
for (var name in objects[prefix]) {
var fullname = (prefix ? prefix + '.' : '') + name;
- var fullnameLower = fullname.toLowerCase()
- if (fullnameLower.indexOf(object) > -1) {
+ if (fullname.toLowerCase().indexOf(object) > -1) {
var score = 0;
- var parts = fullnameLower.split('.');
+ var parts = fullname.split('.');
// check for different match types: exact matches of full name or
// "last name" (i.e. last dotted part)
- if (fullnameLower == object || parts[parts.length - 1] == object) {
+ if (fullname == object || parts[parts.length - 1] == object) {
score += Scorer.objNameMatch;
// matches in last name
} else if (parts[parts.length - 1].indexOf(object) > -1) {
{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;})) {
for (j = 0; j < _files.length; j++) {
file = _files[j];
if (!(file in scoreMap))
- scoreMap[file] = {};
+ scoreMap[file] = {}
scoreMap[file][word] = o.score;
}
});
// create the mapping
for (j = 0; j < files.length; j++) {
file = files[j];
- if (file in fileMap && fileMap[file].indexOf(word) === -1)
+ if (file in fileMap)
fileMap[file].push(word);
else
fileMap[file] = [word];
var valid = true;
// check if all requirements are matched
- 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;
+ if (fileMap[file].length != searchterms.length)
+ continue;
// ensure that none of the excluded terms is in the search result
for (i = 0; i < excluded.length; i++) {
* words. the first one is used to find the occurrence, the
* latter for highlighting it.
*/
- makeSearchSummary : function(htmlText, keywords, hlwords) {
- var text = Search.htmlToText(htmlText);
+ makeSearchSummary : function(text, keywords, hlwords) {
var textLower = text.toLowerCase();
var start = 0;
$.each(keywords, function() {