1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Add support, in PDFFindController, for mixing phrase/word searches (issue 7442)

*Please note:* This patch only extends the `PDFFindController` implementation itself to support this functionality, however it's *purposely* not exposed in the default viewer.

This replaces the previous `phraseSearch`-parameter, and a `query`-string will now always be interpreted as a phrase-search.
To enable searching for individual words, the `query`-parameter must instead consist of an Array of strings. This way it's now also possible to combine phrase/word searches, with a `query`-parameter looking something like `["Lorem ipsum", "foo", "bar"]` which will search for the phrase "Lorem ipsum" *and* the words "foo" respectively "bar".
This commit is contained in:
Jonas Jenwald 2023-04-02 18:40:35 +02:00
parent 4d8a60b435
commit 0e19c3a120
6 changed files with 95 additions and 48 deletions

View file

@ -95,7 +95,6 @@ function testSearch({
query: null,
caseSensitive: false,
entireWord: false,
phraseSearch: true,
findPrevious: false,
matchDiacritics: false,
},
@ -182,7 +181,6 @@ function testEmptySearch({ eventBus, pdfFindController, state }) {
query: null,
caseSensitive: false,
entireWord: false,
phraseSearch: true,
findPrevious: false,
matchDiacritics: false,
},
@ -321,8 +319,7 @@ describe("pdf_find_controller", function () {
eventBus,
pdfFindController,
state: {
query: "alternate solution",
phraseSearch: false,
query: ["alternate", "solution"],
},
matchesPerPage: [0, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0, 0, 0, 0],
selectedMatch: {
@ -332,6 +329,25 @@ describe("pdf_find_controller", function () {
});
});
it("performs a multiple term (phrase) search", async function () {
// Page 9 contains 'alternate solution' and pages 6 and 9 contain
// 'solution'. Both should be found for multiple term (phrase) search.
const { eventBus, pdfFindController } = await initPdfFindController();
await testSearch({
eventBus,
pdfFindController,
state: {
query: ["alternate solution", "solution"],
},
matchesPerPage: [0, 0, 0, 0, 0, 1, 0, 0, 3, 0, 0, 0, 0, 0],
selectedMatch: {
pageIndex: 5,
matchIndex: 0,
},
});
});
it("performs a normal search, where the text is normalized", async function () {
const { eventBus, pdfFindController } = await initPdfFindController(
"fraction-highlight.pdf"