});
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) {
}
}
});
- console.log(data);
$this.fluidbook.search.setHighlightTerms(data.terms);
$this.fluidbook.search.highlightSearchTerms($this.fluidbook.currentPage);
if (callback != undefined) {
}
,
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();
this.termsToHighlight = [];
this.highlights = [];
this.highlightEnabled = fluidbook.datas.highlightResults;
+
this.init();
}
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];
return source;
},
setHighlightTerms: function (terms) {
- if(!this.highlightEnabled){
+ if (!this.highlightEnabled) {
return;
}
this.termsToHighlight = terms;
$("#searchHighlights").html('');
},
highlightSearchTerms: function (pageNr) {
- if(!this.highlightEnabled){
+ if (!this.highlightEnabled) {
return;
}
this.clearHighlights();