Merge pull request #5579 from jazzy-em/master

Added multiple term search functionality (with default phrase search)
This commit is contained in:
Yury Delendik 2016-05-27 14:23:26 -05:00
commit 5aefce6ba6
7 changed files with 154 additions and 16 deletions

View file

@ -116,7 +116,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
this.divContentDone = true;
},
convertMatches: function TextLayerBuilder_convertMatches(matches) {
convertMatches: function TextLayerBuilder_convertMatches(matches,
matchesLength) {
var i = 0;
var iIndex = 0;
var bidiTexts = this.textContent.items;
@ -124,7 +125,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
var queryLen = (this.findController === null ?
0 : this.findController.state.query.length);
var ret = [];
if (!matches) {
return ret;
}
for (var m = 0, len = matches.length; m < len; m++) {
// Calculate the start position.
var matchIdx = matches[m];
@ -147,7 +150,11 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
};
// Calculate the end position.
matchIdx += queryLen;
if (matchesLength) { // multiterm search
matchIdx += matchesLength[m];
} else { // phrase search
matchIdx += queryLen;
}
// Somewhat the same array as above, but use > instead of >= to get
// the end position right.
@ -289,8 +296,14 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
// Convert the matches on the page controller into the match format
// used for the textLayer.
this.matches = this.convertMatches(this.findController === null ?
[] : (this.findController.pageMatches[this.pageIdx] || []));
var pageMatches, pageMatchesLength;
if (this.findController !== null) {
pageMatches = this.findController.pageMatches[this.pageIdx] || null;
pageMatchesLength = (this.findController.pageMatchesLength) ?
this.findController.pageMatchesLength[this.pageIdx] || null : null;
}
this.matches = this.convertMatches(pageMatches, pageMatchesLength);
this.renderMatches(this.matches);
},