Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to implement multi phrase search #10242

Closed
dgoiko opened this issue Nov 8, 2018 · 4 comments

Comments

@dgoiko
Copy link

commented Nov 8, 2018

I'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);
    }
}
@timvandermeij

This comment has been minimized.

Copy link
Contributor

commented Nov 8, 2018

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.

@dgoiko

This comment has been minimized.

Copy link
Author

commented Nov 8, 2018

I thought it was working, but it was a browser glitch, it still doesnt work :S

@damianfabian

This comment has been minimized.

Copy link

commented May 29, 2019

Where you able to solve this @dgoiko?

@dgoiko

This comment has been minimized.

Copy link
Author

commented Jun 23, 2019

@damianfabian not really, it was buggy so I did not polst it, although this is on my schedule list for a future project, so I'll post updates when I get into this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.