summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/book.js b/lib/book.js
index a7d0cd5..84d3c6b 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -19,6 +19,8 @@ var PluginsList = require("./pluginslist");
var generators = require("./generators");
+var SEARCHINDEX_MAXSIZE = 1000000;
+
var Book = function(root, context, parent) {
this.context = _.defaults(context || {}, {
// Extend book configuration
@@ -79,6 +81,8 @@ var Book = function(root, context, parent) {
this.langsFile = null;
// Search Index
+ this.searchIndexEnabled = true;
+ this.searchIndexSize = 0;
this.searchIndex = lunr(function () {
this.ref("url");
@@ -738,13 +742,25 @@ Book.prototype.contentLink = function(link) {
// Index a page into the search index
Book.prototype.indexPage = function(page) {
var nav = this.navigation[page.path];
- if (!nav) return;
+ if (!nav || !this.searchIndexEnabled) return;
this.log.debug.ln("index page", page.path);
+
+ // Extract text from the page
+ var text = pageUtil.extractText(page.sections);
+
+ // Limit size of index (to avoid #941)
+ this.searchIndexSize = this.searchIndexSize + text.length;
+ if (this.searchIndexSize > SEARCHINDEX_MAXSIZE) {
+ this.log.warn.ln("search index is too big, indexing is now disabled");
+ this.searchIndexEnabled = false;
+ return;
+ }
+
this.searchIndex.add({
url: this.contentLink(page.path),
title: nav.title,
- body: pageUtil.extractText(page.sections),
+ body: text
});
};