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 :-)

@st0012 st0012 requested a review from vinistock October 28, 2025 12:24
@st0012
Copy link
Member Author

st0012 commented Oct 28, 2025

But I imagine that rdoc doesn't have a way to weight certain classes over others.

Yeah the generated site is completely static and there's no way we can collect that info. We may get some insight if docs.ruby-lang.org collects some statistics. But we'd still have no ways to insert those weights without significantly changing RDoc as you said.

@colby-swandale
Copy link
Member

@st0012 I have list of boosts that I use for Ruby API, I would be interested to see if this is something RDoc could use in its search.

https://github.com/rubyapi/rubyapi/blob/50cf34d2b96ff799a3cb75994edbf06172305ec9/app/models/ruby_object.rb#L2-L34

@st0012
Copy link
Member Author

st0012 commented Oct 30, 2025

@colby-swandale Thanks that's definitely helpful! I don't think this should be baked in RDoc directly given that it's technically a static site generator for all Ruby projects.
But it may be possible to take a yaml in .rdoc_options list as weights 🤔

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

6 participants