]> _ Git - fluidbook-html5.git/commitdiff
wip #1668 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Sep 2017 16:30:25 +0000 (18:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Sep 2017 16:30:25 +0000 (18:30 +0200)
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.search.js

index 0c981ac428ace59b19eb81c0c3a8814ab7869067..2ff581bae89dcdd899100ee2dec5240cfbf9dcaf 100644 (file)
@@ -155,8 +155,10 @@ FluidbookMenu.prototype = {
             });
             var e = encodeURIComponent($this.searchString);
             $(".mview .doubleThumb").each(function () {
-
                 var pages = $(this).data('pages').toString().split(',');
+                if (pages.indexOf('1') != -1) {
+                    pages.push('0');
+                }
                 var hitsp = 0;
                 var pagesWithHits = [];
                 for (var i in pages) {
@@ -192,7 +194,6 @@ FluidbookMenu.prototype = {
                     }
                 }
             });
-            console.log(data);
             $this.fluidbook.search.setHighlightTerms(data.terms);
             $this.fluidbook.search.highlightSearchTerms($this.fluidbook.currentPage);
             if (callback != undefined) {
@@ -329,7 +330,7 @@ FluidbookMenu.prototype = {
     }
     ,
     openShare: function (p1, p2, callback) {
-        this.fluidbook.share.openShare(p1,p2,callback);
+        this.fluidbook.share.openShare(p1, p2, callback);
     },
     openBookmark: function (p1, p2, callback) {
         var view = this.fluidbook.bookmarks.getView();
index 14dea88654cff44e5cd3b343ae563effcd8e3e28..a4a36a6d842d4fcb9b0c680d19b28a7be066a377 100644 (file)
@@ -4,6 +4,7 @@ function FluidbookSearch(fluidbook) {
     this.termsToHighlight = [];
     this.highlights = [];
     this.highlightEnabled = fluidbook.datas.highlightResults;
+
     this.init();
 }
 
@@ -71,38 +72,71 @@ FluidbookSearch.prototype = {
         callback(res.slice(0, 12));
     },
     _find: function (q, callback) {
+
         var words = this.normalizeQuery(q);
         var res = {};
         var terms = [];
         var total = 0;
+        var doublesPages = {};
+
+        // var allPages=Array.apply(null, Array(this.fluidbook.datas.pages)).map(function (_, i) {return i+1;});
+
+
         var q, v, k, kk, word, wordata, page, occurences;
 
         for (kk in words) {
             q = words[kk];
             terms.push(q);
             for (k in INDEX) {
-                v = INDEX[k];
-                if (k.indexOf(q) != 0) {
+
+                if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'begins' && k.indexOf(q) != 0) {
+                    continue;
+                } else if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'contains' && k.indexOf(q) == -1) {
+                    continue;
+                } else if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'exact' && k != q) {
                     continue;
                 }
-
+                v = INDEX[k];
                 for (page in v.p) {
                     var occurences = v.p[page];
                     page = parseInt(page);
-                    if (res[page] == undefined) {
-                        res[page] = 0;
+                    if ((page % 2) == 1) {
+                        page--;
+                    }
+                    if (doublesPages[page] == undefined) {
+                        doublesPages[page] = {};
+                    }
+                    if (doublesPages[page][kk] == undefined) {
+                        doublesPages[page][kk] = 0;
                     }
-                    res[page] += occurences;
+                    doublesPages[page][kk] += occurences;
                     total += occurences;
                 }
             }
         }
 
-        callback({
+        var nbwords = words.length;
+
+        total = 0;
+        for (var dpNumber in doublesPages) {
+            var doublePageOccurences = doublesPages[dpNumber];
+            if (Object.keys(doublePageOccurences).length == nbwords || this.fluidbook.datas.searchPageSelectionAlgorithm == 'OR') {
+                var occ = 0;
+                for (var ww in doublePageOccurences) {
+                    occ += doublePageOccurences[ww];
+                }
+                res[dpNumber] = occ;
+                total += occ;
+            }
+        }
+
+        var returnVal = {
             total: total,
             results: res,
             terms: terms
-        });
+        };
+
+        callback(returnVal);
     },
     sortHints: function (a, b) {
         return b[1] - a[1];
@@ -143,7 +177,7 @@ FluidbookSearch.prototype = {
         return source;
     },
     setHighlightTerms: function (terms) {
-        if(!this.highlightEnabled){
+        if (!this.highlightEnabled) {
             return;
         }
         this.termsToHighlight = terms;
@@ -165,7 +199,7 @@ FluidbookSearch.prototype = {
         $("#searchHighlights").html('');
     },
     highlightSearchTerms: function (pageNr) {
-        if(!this.highlightEnabled){
+        if (!this.highlightEnabled) {
             return;
         }
         this.clearHighlights();