diff options
-rw-r--r-- | lib/book.js | 20 | ||||
-rw-r--r-- | package.json | 2 |
2 files changed, 19 insertions, 3 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 }); }; diff --git a/package.json b/package.json index fe74579..079ea09 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "lib/index.js", "dependencies": { "q": "1.0.1", - "lunr": "0.5.7", + "lunr": "0.5.12", "lodash": "3.10.1", "graceful-fs": "3.0.5", "resolve": "0.6.3", |