From: Vincent Vanwaelscappel Date: Fri, 14 Mar 2014 16:27:25 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=55b9782a3339425e2a1ce3a7b13d729e35c08ae3;p=fluidbook-html5.git --- diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 8b50d207..e58a22d5 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -1,109 +1,109 @@ -function FluidbookSearch() { -} - -FluidbookSearch.prototype = { - getHints: function(q) { - var words = this.normalizeQuery(q); - q = words.pop(); - var res = []; - - if (q.length < 3) { - return res; - } - - var v; - for (var k in INDEX) { - v = INDEX[k]; - if (k.indexOf(q) != 0) { - continue; - } - res.push([k, v.t]); - } - - res.sort(this.sortHints); - return res.slice(0, 12); - }, - find: function(q) { - var words = this.normalizeQuery(q); - - var res = {}; - var terms = []; - var total=0; - - var q, v, k, kk, word, wordata, page, occurences; - for (kk in words) { - q = words[kk]; - - for (k in INDEX) { - v = INDEX[k]; - if (k.indexOf(q) != 0) { - continue; - } - for (word in v.w) { - wordata = v.w[word]; - terms.push(word); - for (page in wordata.p) { - - occurences = wordata.p[page]; - - page = parseInt(page); - - - if (res[page] == undefined) { - res[page] = 0; - } - res[page] += occurences; - total+=occurences; - } - } - } - } - - return { - total:total, - results: res, - terms: terms.join(' ') - }; - }, - sortHints: function(a, b) { - return b[1] - a[1]; - }, - kill: function() { - - }, - normalizeQuery: function(q) { - q = this.noAccents(q); - q = q.toLowerCase(); - return q.split(' '); - }, - noAccents: function(source) { - source = source.replace(/[àáâãäå]/g, "a"); - source = source.replace(/[ÀÁÂÃÄÅ]/g, "A"); - source = source.replace(/[èéêë]/g, "e"); - source = source.replace(/[ËÉÊÈ]/g, "E"); - source = source.replace(/[ìíîï]/g, "i"); - source = source.replace(/[ÌÍÎÏ]/g, "I"); - source = source.replace(/[ðòóôõöø]/g, "o"); - source = source.replace(/[ÐÒÓÔÕÖØ]/g, "O"); - source = source.replace(/[ùúûü]/g, "u"); - source = source.replace(/[ÙÚÛÜ]/g, "U"); - source = source.replace(/[ýýÿ]/g, "y"); - source = source.replace(/[ÝÝŸ]/g, "Y"); - source = source.replace(/[ç]/g, "c"); - source = source.replace(/[Ç]/g, "C"); - source = source.replace(/[ñ]/g, "n"); - source = source.replace(/[Ñ]/g, "N"); - source = source.replace(/[š]/g, "s"); - source = source.replace(/[Š]/g, "S"); - source = source.replace(/[ž]/g, "z"); - source = source.replace(/[Ž]/g, "Z"); - source = source.replace(/[æ]/g, "ae"); - source = source.replace(/[Æ]/g, "AE"); - source = source.replace(/[œ]/g, "oe"); - source = source.replace(/[Œ]/g, "OE"); - return source; - - } -}; - - \ No newline at end of file +function FluidbookSearch() { + loadJsLibrary('data/search.index.js'); +} + +FluidbookSearch.prototype = { + getHints: function(q) { + var words = this.normalizeQuery(q); + q = words.pop(); + var res = []; + + if (q.length < 3) { + return res; + } + + var v; + for (var k in INDEX) { + v = INDEX[k]; + if (k.indexOf(q) != 0) { + continue; + } + res.push([k, v.t]); + } + + res.sort(this.sortHints); + return res.slice(0, 12); + }, + find: function(q) { + var words = this.normalizeQuery(q); + + var res = {}; + var terms = []; + var total = 0; + + var q, v, k, kk, word, wordata, page, occurences; + for (kk in words) { + q = words[kk]; + + for (k in INDEX) { + v = INDEX[k]; + if (k.indexOf(q) != 0) { + continue; + } + for (word in v.w) { + wordata = v.w[word]; + terms.push(word); + for (page in wordata.p) { + + occurences = wordata.p[page]; + + page = parseInt(page); + + + if (res[page] == undefined) { + res[page] = 0; + } + res[page] += occurences; + total += occurences; + } + } + } + } + + return { + total: total, + results: res, + terms: terms.join(' ') + }; + }, + sortHints: function(a, b) { + return b[1] - a[1]; + }, + kill: function() { + + }, + normalizeQuery: function(q) { + q = this.noAccents(q); + q = q.toLowerCase(); + return q.split(' '); + }, + noAccents: function(source) { + source = source.replace(/[àáâãäå]/g, "a"); + source = source.replace(/[ÀÁÂÃÄÅ]/g, "A"); + source = source.replace(/[èéêë]/g, "e"); + source = source.replace(/[ËÉÊÈ]/g, "E"); + source = source.replace(/[ìíîï]/g, "i"); + source = source.replace(/[ÌÍÎÏ]/g, "I"); + source = source.replace(/[ðòóôõöø]/g, "o"); + source = source.replace(/[ÐÒÓÔÕÖØ]/g, "O"); + source = source.replace(/[ùúûü]/g, "u"); + source = source.replace(/[ÙÚÛÜ]/g, "U"); + source = source.replace(/[ýýÿ]/g, "y"); + source = source.replace(/[ÝÝŸ]/g, "Y"); + source = source.replace(/[ç]/g, "c"); + source = source.replace(/[Ç]/g, "C"); + source = source.replace(/[ñ]/g, "n"); + source = source.replace(/[Ñ]/g, "N"); + source = source.replace(/[š]/g, "s"); + source = source.replace(/[Š]/g, "S"); + source = source.replace(/[ž]/g, "z"); + source = source.replace(/[Ž]/g, "Z"); + source = source.replace(/[æ]/g, "ae"); + source = source.replace(/[Æ]/g, "AE"); + source = source.replace(/[œ]/g, "oe"); + source = source.replace(/[Œ]/g, "OE"); + return source; + + } +}; + diff --git a/js/main.js b/js/main.js index 704071ad..1b815fbc 100644 --- a/js/main.js +++ b/js/main.js @@ -395,8 +395,6 @@ try { if (!startAfterLoading) { fluidbook.changeAddress(); } - - loadJsLibrary('data/search.index.js'); } } catch (err) {