Skip to content

Search results prioritize alphabetical order + exact matches over results that start with a substring #453

Description

@vivaria

Hi there! Lovely theme. I use it for a site that helps searching for card rulings in a card game: https://edisonrul.ing/

I noticed that when the search query is incomplete, the results are unintituitive. For example, searching for the card "Lonefire Blossom", I would expect it to show up near the top of the results after "Lon" or "Lone". However, this is what I see instead:

1. Lon

Details Image

Cards that contain lon but don't start with lon are prioritized (alphabetical order), such that "Lone" cards are buried in the results.

2. Lone

Details Image

Now that the search has found exact matches ("Lone Wolf"), all of the other partial matches are excluded from the preview. (Note: Typing in "Lonef" instead will cause the non-exact matches to return again.)


Is it possible that this behavior is due to the weighting in sphinx_search.ts?

// query matches the full name of an object
objNameMatch: 11,
// or matches in the last dotted part of the object name
objPartialMatch: 6,
// Additive scores depending on the priority of the object
objPrio: {
0: 15, // used to be importantResults
1: 5, // used to be objectResults
2: -5
} as Record<number, number>, // used to be unimportantResults
// Used when the priority is not in the mapping.
objPrioDefault: 0,
// query found in title
title: 15,
partialTitle: 7,
// query found in terms
term: 5,
partialTerm: 2
}

I notice that the lunr.js implementation on the mkdocs-material site doesn't seem to suffer from these same issues. For example, searching for "Se" will return "Setup" and "Setting up your site" before "Built-in search plugins" (i.e. non-alphabetical). Hence my thinking that this behavior might be due to sphinx-immaterial's own search weighting.

Curious to learn more about how the default search works! Thanks again. <3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: SearchRelated to search feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions