Trying to implement multi phrase search
See original GitHub issueI’m trying to implement a combined word and phrase function like the one referenced in #7442 , however I’m having some trouble.
I added this to PDFLinkService (pdf.js version 2.0.943):
if ('busq' in params) {
var busqJSON = params['busq'];
var complexSearch = JSON.parse(busqJSON);
var simpleTerms = [];
if(Array.isArray(complexSearch)){
var i;
for(i=0; i<complexSearch.length;i++){
var term = complexSearch[i].trim();
if(term.includes(" ")){
this.eventBus.dispatch('findfromurlhashdail', {
source: this,
query: term,
phraseSearch: true
});
}else{
simpleTerms.push(term);
}
}
if(simpleTerms.length > 0){
this.eventBus.dispatch('findfromurlhashdail', {
source: this,
query: simpleTerms.join(' '),
phraseSearch: false
});
}
}
}
findfromurlhashdail is basically the same than findfromurlhash but with exact word match enabled by default. You could change it with findfromurlhash and it will work.
If you provide a query string like this:
#busq=['phrase one', 'phrase two', 'word1', 'word2']
it searches and highlights “phrase one” using phraseSearch mode, then searches for “phrase one”, and then for “word1 word2” in single word mode.
Everything works as expected, except that every search cleans the highlights from the previous one (I’ve checked it with debugger).
Am I doing this the right way?
EDIT: As suggested, I edited updateMatches function. It doesnt work either:
{
key: 'updateMatches ',
value: function updateMatches () {
if (!this.renderingDone) {
return;
}
var matches = this.matches;
var textDivs = this.textDivs;
if (!this.findController || !this.findController.highlightMatches) {
return;
}
var pageMatches = void 0,
pageMatchesLength = void 0;
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);
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
If you do a new search, then
_updateMatches
is called at https://github.com/mozilla/pdf.js/blob/master/web/text_layer_builder.js#L288 which clears all existing matches at https://github.com/mozilla/pdf.js/blob/master/web/text_layer_builder.js#L298. If you need this behavior to be different, you should change it there.How have you got on with this project? We are trying to do something similar and attempting to find where we can put the _calculateArrayMatch() but we arent having much luck, using the repo to try and find where this is located and found it in pdf_find_controller.js and not in the text_layer_builder.js as suggested above. Any thoughts or ideas welcome please 😃