Skip to content

Conversation

@wlach
Copy link
Contributor

@wlach wlach commented May 25, 2024

Feature or Bugfix

  • Bugfix

Purpose

Trying to make sure that title matches don't get unnecessary prominence. Intended as a proof of concept, not a full solution.

Detail

TBD

Relates

Related to sphinx-doc#12391. Intended as a proof of concept, not a full solution.
@wlach
Copy link
Contributor Author

wlach commented May 25, 2024

Before:
image
After:
image

for (const [title, foundTitles] of Object.entries(allTitles)) {
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
for (const [file, id] of foundTitles) {
let score = Math.round(100 * queryLower.length / title.length)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

100 appears to be a total magic number AFAICT

// score these a little bit above document matches, with more of a boost
// for main document titles
let baseScore = Scorer.title + (isMainTitle ? 2 : 1)
let score = Math.round(baseScore * queryLower.length / title.length)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
let score = Math.round(baseScore * queryLower.length / title.length)
let baseScore = (isMainTitle ? Scorer.title : Scorer.partialTitle) + 1

Got more relevant results by doing the above, but it feels even more hacky. Also comes at the cost of pushing subtitle matches even further down.

image

@jayaddison
Copy link
Contributor

I've rolled this into the test coverage added by #12441, and it allows those tests to pass (with one small unrelated test failure that occurred due to a score-change on an existing test), and then applied some adjustments/refactoring - let me know what you think!

@wlach
Copy link
Contributor Author

wlach commented Jun 25, 2024

#12441 looks good! Let's close this in favour of that, this was only intended as a prototype.

@wlach wlach closed this Jun 25, 2024
@wlach wlach deleted the boost-scores-if-main-title branch June 25, 2024 00:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants