Skip to content

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Oct 13, 2025

I know adding 2 new phases for exact matches feels like a workaround, but without a more thorough review on the entire searching algorithm this is the best solution I have.

I also added basic tests for search.js using mini_racer gem (dev dependency) to simulate JS evaluation. I chose this approach because it should be simpler than maintaining a whole set of JS dependencies and setups.

Fixes #1194

@matzbot
Copy link
Collaborator

matzbot commented Oct 13, 2025

🚀 Preview deployment available at: https://dcca3028.rdoc-6cd.pages.dev (commit: b3dcacc)

When searching for a class name like "String", the search should
return exact matches first before returning classes that contain
the search term in their name (like "Prism::StringNode").

This adds a new pass 0 to the search algorithm that only matches
when the searchIndex exactly equals the query. The previous passes
are shifted accordingly:
- Pass 0: exact match (new)
- Pass 1: searchIndex starts with query (was pass 0)
- Pass 2: longSearchIndex starts with query (was pass 1)
- Pass 3: searchIndex contains query (was pass 2)
- Pass 4: regexp match (was pass 3)

Fixes #1194
@KieranP
Copy link

KieranP commented Oct 23, 2025

Another great improvement would be to order results by most common classes first. Consider https://docs.ruby-lang.org/en/master?q=empty%3F - The top 5 results are Array, Dir, ENV, File, and FileTest. Arguably, the most useful ordering would be String, Array, Hash, Set, and Symbol.

But I imagine that rdoc doesn't have a way to weight certain classes over others. And then there would probably be some contested discussions around how things should be weighted., so this may never happen, but I wanted to throw the idea out there, just in case :-)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

curious search result order on docs.ruby-lang.org

4 participants