mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Moved searchindex to the bottom to not lock the search page, prepared index for title searching.
This commit is contained in:
parent
3debdc2c2a
commit
b69e1a4fe7
@ -59,6 +59,7 @@ class Stemmer(PorterStemmer):
|
||||
"""
|
||||
|
||||
def stem(self, word):
|
||||
word = word.lower()
|
||||
return PorterStemmer.stem(self, word, 0, len(word) - 1)
|
||||
|
||||
|
||||
@ -139,9 +140,17 @@ class IndexBuilder(object):
|
||||
|
||||
visitor = WordCollector(doctree)
|
||||
doctree.walk(visitor)
|
||||
for word in word_re.findall(title) + visitor.found_words:
|
||||
self._mapping.setdefault(self._stemmer.stem(word.lower()),
|
||||
set()).add(filename)
|
||||
|
||||
def add_term(word, prefix=''):
|
||||
word = self._stemmer.stem(word)
|
||||
self._mapping.setdefault(prefix + word, set()).add(filename)
|
||||
|
||||
for word in word_re.findall(title):
|
||||
add_term(word)
|
||||
add_term(word, 'T')
|
||||
|
||||
for word in visitor.found_words:
|
||||
add_term(word)
|
||||
|
||||
|
||||
class SearchFrontend(object):
|
||||
@ -177,6 +186,6 @@ class SearchFrontend(object):
|
||||
word = word[1:]
|
||||
else:
|
||||
storage = required
|
||||
storage.add(self._stemmer.stem(word.lower()))
|
||||
storage.add(self._stemmer.stem(word))
|
||||
|
||||
return self.query(required, excluded)
|
||||
|
@ -5,14 +5,14 @@
|
||||
* words. the first one is used to find the occurance, the
|
||||
* latter for highlighting it.
|
||||
*/
|
||||
|
||||
jQuery.makeSearchSummary = function(text, keywords, hlwords) {
|
||||
var textLower = text.toLowerCase();
|
||||
var start = 0;
|
||||
$.each(keywords, function() {
|
||||
var i = textLower.indexOf(this.toLowerCase());
|
||||
if (i > -1) {
|
||||
if (i > -1)
|
||||
start = i;
|
||||
}
|
||||
});
|
||||
start = Math.max(start - 120, 0);
|
||||
var excerpt = ((start > 0) ? '...' : '') +
|
||||
@ -80,9 +80,8 @@ var PorterStemmer = function() {
|
||||
var firstch;
|
||||
var origword = w;
|
||||
|
||||
if (w.length < 3) {
|
||||
if (w.length < 3)
|
||||
return w;
|
||||
}
|
||||
|
||||
var re;
|
||||
var re2;
|
||||
@ -90,20 +89,17 @@ var PorterStemmer = function() {
|
||||
var re4;
|
||||
|
||||
firstch = w.substr(0,1);
|
||||
if (firstch == "y") {
|
||||
if (firstch == "y")
|
||||
w = firstch.toUpperCase() + w.substr(1);
|
||||
}
|
||||
|
||||
// Step 1a
|
||||
re = /^(.+?)(ss|i)es$/;
|
||||
re2 = /^(.+?)([^s])s$/;
|
||||
|
||||
if (re.test(w)) {
|
||||
if (re.test(w))
|
||||
w = w.replace(re,"$1$2");
|
||||
}
|
||||
else if (re2.test(w)) {
|
||||
else if (re2.test(w))
|
||||
w = w.replace(re2,"$1$2");
|
||||
}
|
||||
|
||||
// Step 1b
|
||||
re = /^(.+?)eed$/;
|
||||
@ -125,17 +121,16 @@ var PorterStemmer = function() {
|
||||
re2 = /(at|bl|iz)$/;
|
||||
re3 = new RegExp("([^aeiouylsz])\\1$");
|
||||
re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
||||
if (re2.test(w)) {
|
||||
if (re2.test(w))
|
||||
w = w + "e";
|
||||
}
|
||||
else if (re3.test(w)) {
|
||||
re = /.$/; w = w.replace(re,"");
|
||||
re = /.$/;
|
||||
w = w.replace(re,"");
|
||||
}
|
||||
else if (re4.test(w)) {
|
||||
else if (re4.test(w))
|
||||
w = w + "e";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1c
|
||||
re = /^(.+?)y$/;
|
||||
@ -143,7 +138,8 @@ var PorterStemmer = function() {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
re = new RegExp(s_v);
|
||||
if (re.test(stem)) { w = stem + "i"; }
|
||||
if (re.test(stem))
|
||||
w = stem + "i";
|
||||
}
|
||||
|
||||
// Step 2
|
||||
@ -153,10 +149,9 @@ var PorterStemmer = function() {
|
||||
stem = fp[1];
|
||||
suffix = fp[2];
|
||||
re = new RegExp(mgr0);
|
||||
if (re.test(stem)) {
|
||||
if (re.test(stem))
|
||||
w = stem + step2list[suffix];
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3
|
||||
re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
|
||||
@ -165,10 +160,9 @@ var PorterStemmer = function() {
|
||||
stem = fp[1];
|
||||
suffix = fp[2];
|
||||
re = new RegExp(mgr0);
|
||||
if (re.test(stem)) {
|
||||
if (re.test(stem))
|
||||
w = stem + step3list[suffix];
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4
|
||||
re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
|
||||
@ -177,18 +171,16 @@ var PorterStemmer = function() {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
re = new RegExp(mgr1);
|
||||
if (re.test(stem)) {
|
||||
if (re.test(stem))
|
||||
w = stem;
|
||||
}
|
||||
}
|
||||
else if (re2.test(w)) {
|
||||
var fp = re2.exec(w);
|
||||
stem = fp[1] + fp[2];
|
||||
re2 = new RegExp(mgr1);
|
||||
if (re2.test(stem)) {
|
||||
if (re2.test(stem))
|
||||
w = stem;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5
|
||||
re = /^(.+?)e$/;
|
||||
@ -198,10 +190,9 @@ var PorterStemmer = function() {
|
||||
re = new RegExp(mgr1);
|
||||
re2 = new RegExp(meq1);
|
||||
re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
||||
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) {
|
||||
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
|
||||
w = stem;
|
||||
}
|
||||
}
|
||||
re = /ll$/;
|
||||
re2 = new RegExp(mgr1);
|
||||
if (re.test(w) && re2.test(w)) {
|
||||
@ -210,15 +201,13 @@ var PorterStemmer = function() {
|
||||
}
|
||||
|
||||
// and turn initial Y back to y
|
||||
if (firstch == "y") {
|
||||
if (firstch == "y")
|
||||
w = firstch.toLowerCase() + w.substr(1);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Search Module
|
||||
*/
|
||||
@ -267,13 +256,11 @@ var Search = {
|
||||
function pulse() {
|
||||
Search._pulse_status = (Search._pulse_status + 1) % 4;
|
||||
var dotString = '';
|
||||
for (var i = 0; i < Search._pulse_status; i++) {
|
||||
for (var i = 0; i < Search._pulse_status; i++)
|
||||
dotString += '.';
|
||||
}
|
||||
Search.dots.text(dotString);
|
||||
if (Search._pulse_status > -1) {
|
||||
if (Search._pulse_status > -1)
|
||||
window.setTimeout(pulse, 500);
|
||||
}
|
||||
};
|
||||
pulse();
|
||||
},
|
||||
@ -320,9 +307,8 @@ var Search = {
|
||||
hlwords.push(tmp[i].toLowerCase());
|
||||
}
|
||||
// only add if not already in the list
|
||||
if (!$.contains(toAppend, word)) {
|
||||
if (!$.contains(toAppend, word))
|
||||
toAppend.push(word);
|
||||
}
|
||||
};
|
||||
var highlightstring = '?highlight=' + $.urlencode(hlwords.join(" "));
|
||||
|
||||
@ -413,12 +399,10 @@ var Search = {
|
||||
else {
|
||||
Search.stopPulse();
|
||||
Search.title.text(_('Search Results'));
|
||||
if (!resultCount) {
|
||||
if (!resultCount)
|
||||
Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
|
||||
}
|
||||
else {
|
||||
else
|
||||
Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
|
||||
}
|
||||
Search.status.fadeIn(500);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% extends "layout.html" %}
|
||||
{% set title = _('Search') %}
|
||||
{% set script_files = script_files + ['_static/searchtools.js', 'searchindex.js'] %}
|
||||
{% set script_files = script_files + ['_static/searchtools.js'] %}
|
||||
{% block body %}
|
||||
<h1 id="search-documentation">{{ _('Search') }}</h1>
|
||||
<p>
|
||||
@ -32,3 +32,7 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block footer %}
|
||||
{{ super() }}
|
||||
<script type="text/javascript" src="searchindex.js"></script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user