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

x/pkgsite: "jump to" search improvement #42489

Closed
eliben opened this issue Nov 10, 2020 · 4 comments
Closed

x/pkgsite: "jump to" search improvement #42489

eliben opened this issue Nov 10, 2020 · 4 comments

Comments

@eliben
Copy link
Member

@eliben eliben commented Nov 10, 2020

What is the URL of the page with the issue?

https://pkg.go.dev/github.com/gin-gonic/gin

What is your user agent?

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36

What did you do?

I really like the "jump to" feature ('f' keyboard shortcut).

I press 'f', then 'H' in the search box. gin has a type named H which I was hoping to find easily.

What did you expect to see?

I'd expect the H type at the top, or close to it.

What did you see instead?

A whole bunch of test results before the H type is shown:

AuthUserKey constant
BasicAuth function
BasicAuthForRealm function
Context.AbortWithError method
Context.AbortWithStatus method
Context.AbortWithStatusJSON method
Context.BindHeader method
Context.BindWith method
Context.FileAttachment method
Context.FullPath method
Context.GetHeader method
Context.Handler method
...
...

This search should be more than just subset match. It should prioritize whole matches (e.g. if I search foo, match a whole function named foo before barfoo and before foobar), early matches (e.g. search for foo shows foobar before barfoo), and so on.

As of now, this search is less useful than it could be due to this (and it could be very useful indeed!!)

@gopherbot gopherbot added the pkgsite label Nov 10, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 10, 2020
@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Nov 10, 2020

Thank you for the feedback! Is this what you expected to see after typing H?

Screen Shot 2020-11-10 at 5 47 59 PM

If you are interested in contributing an improvement for this feature, feel free to send us a CL!

Also /cc @jba

@eliben
Copy link
Member Author

@eliben eliben commented Nov 10, 2020

Thank you for the feedback! Is this what you expected to see after typing H?

Yes, that would be the best outcome! The plain (full match) H comes first, and then come strings starting with H before other strings that just have h randomly in them somewhere.

If you are interested in contributing an improvement for this feature, feel free to send us a CL!

I'll take a look to evaluate.

@eliben
Copy link
Member Author

@eliben eliben commented Nov 11, 2020

Your JS code is very clean and easy to grok, kudos :-)

The current algorithm is coded in https://github.com/golang/pkgsite/blob/244535af9dc4b75ff3d387c93e35c60467cbf85e/content/static/js/jump.js#L152

A case-insensitive regexp for the search filter is matched with each potential item in the jump list, and the matching ones are shown - in order of original appearance (which is the alphabetic order). To fix this, the algorithm can be modified as follows:

  • Iterate the jump list, collecting 3 lists:
    • Exact matches (there can be only one, maybe two with case insensitivity)
    • Prefix matches
    • Other matches

Then concatenate them in the order outlined above and display.


I'm looking into setting up a local pkgsite instance to try this

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 12, 2020

Change https://golang.org/cl/269278 mentions this issue: x/pkgsite: more accurate identifier filtering for "jump to" in-page search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants