question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to implement multi phrase search

See original GitHub issue

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);
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
timvandermeijcommented, 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.

0reactions
michael-leesecommented, Mar 19, 2021

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Searching for Multiple Words and Phrases - Peachpit
The most important search strategies to learn for any search engine are the techniques the site provides to look for multiple words and ......
Read more >
6 Chrome Extensions to Search for Multiple Words on a ...
Do you ever find yourself needing to search things on a webpage? Don't stick to CTRL + F, use these more powerful extensions...
Read more >
Multi-"match-phrase" query in Elastic Search - Stack Overflow
I want to match all documents that contain either phrases exactly as entered. elasticsearch · elasticsearch-query · match-phrase · Share.
Read more >
6. Phrase Searching, Wildcards and Proximity Operators
Ovid databases search for multiple words as a phrase automatically. ... To use truncation, enter the root of the word with the truncation ......
Read more >
Search operators you can use with Gmail - Google Support
Want to get more out of Google apps at work or school? ... You can use words or symbols called search operators to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found