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

HTML Search: Fix multiple term matching edge case #11960

Merged
merged 7 commits into from
Mar 3, 2024

Conversation

wlach
Copy link
Contributor

@wlach wlach commented Feb 6, 2024

Subject: Fix multiple term matching edge case

Feature or Bugfix

  • Bugfix

Purpose

Fixes multiple matches getting accidentally overwritten in certain rare cases

Detail

In certain rare cases, term matches could get overwritten due to a logic bug in the search code. Fix this and add a test.

Relates

Closes #11959

tests/js/searchtools.js Outdated Show resolved Hide resolved
@wlach wlach marked this pull request as ready for review February 6, 2024 16:09
@jayaddison
Copy link
Contributor

Two nitpicks with the test case:

  • Could you omit the objtypes and any other non-essential properties of the test fixture?
  • Adding a newline between the setup phase of the test (creating and setting the index) and the assertion/expectation phase (creating the expected hits list and running expect) could provide a useful hint to readers about how the test is structured.

@wlach wlach requested a review from jayaddison February 6, 2024 23:07
@wlach
Copy link
Contributor Author

wlach commented Feb 6, 2024

Two nitpicks with the test case:

* Could you omit the `objtypes` and any other non-essential properties of the test fixture?

* Adding a newline between the setup phase of the test (creating and setting the index) and the assertion/expectation phase (creating the expected `hits` list and running `expect`) could provide a useful hint to readers about how the test is structured.

Done! For future reference if you have suggestions using GitHub's "suggest" feature in a comment on the diff is a little easier for me to apply -- see step 6 here:

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#adding-comments-to-a-pull-request

Copy link
Contributor

@jayaddison jayaddison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍

@jayaddison
Copy link
Contributor

I've been fairly cautious about reviewing these search changes because I'd like to understand them in some detail. This one still looks good to me.

One minor suggestion that I have -- frustratingly, GitHub doesn't allow suggestions on line ranges that include unmodified lines, it seems -- would be to aim for consistency with the creation of scoreMap when building fileMap here. That would be something like:

        if (!fileMap.has(file)) fileMap.set(file, [word]);
        else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);

...however: that's optional, and again I think this pull request is in good shape.

@wlach
Copy link
Contributor Author

wlach commented Mar 2, 2024

One minor suggestion that I have -- frustratingly, GitHub doesn't allow suggestions on line ranges that include unmodified lines, it seems -- would be to aim for consistency with the creation of scoreMap when building fileMap here. That would be something like:
...

In JavaScript it's generally considered best practice to always use curly braces in a conditional clause: https://eslint.org/docs/latest/rules/curly -- especially when there's an else involved.

That said, this would be consistent with the style elsewhere in this file. I guess I'll change it, this PR needs a changelog entry anyway.

Copy link
Contributor

@jayaddison jayaddison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @wlach 👍

@jayaddison jayaddison requested a review from picnixz March 2, 2024 14:22
tests/js/searchtools.js Show resolved Hide resolved
tests/js/searchtools.js Outdated Show resolved Hide resolved
@jayaddison jayaddison added type:bug javascript Pull requests that update Javascript code labels Mar 2, 2024
@wlach wlach requested a review from picnixz March 3, 2024 16:08
@wlach
Copy link
Contributor Author

wlach commented Mar 3, 2024

@jayaddison @picnixz Ok I rebased this on top of master / #11958 so I think it's ready to go in too.

@picnixz
Copy link
Member

picnixz commented Mar 3, 2024

I think it's fine. It'll be the last PR that I'll review for the next 10 days (I'm travelling).

Thank you. If there is some critical things to do next week, ping me or chrisjsewell or jfbu which have write permissions.

@picnixz picnixz merged commit ae51974 into sphinx-doc:master Mar 3, 2024
23 checks passed
@wlach wlach deleted the html-search-issue-11959 branch March 3, 2024 17:03
@wlach
Copy link
Contributor Author

wlach commented Mar 3, 2024

I think it's fine. It'll be the last PR that I'll review for the next 10 days (I'm travelling).

Thank you. If there is some critical things to do next week, ping me or chrisjsewell or jfbu which have write permissions.

No problem, I'll probably just wait for you/others to take a look at the remaining work on their own schedule. If it's been a while I will ping.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
html search javascript Pull requests that update Javascript code type:bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTML Search: Multiple term matching sometimes breaks
3 participants