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

Add search to website #8624

Merged
merged 23 commits into from
Jul 4, 2024
Merged

Add search to website #8624

merged 23 commits into from
Jul 4, 2024

Conversation

aliabd
Copy link
Collaborator

@aliabd aliabd commented Jun 26, 2024

Search!

closes: #2121

While this works really well as it is currently, I will probably need to do another pass to clean out all the regex. The challenge was that for docs especially some of the content exists in jsons and some in the templates. So to get the content in a searchable dictionary i need to render it first, which means i need to remove the html code using regex.

There must be a better way to do this, and hopefully its a way that will let us link to specific ids on the page so that the user can get closer to the query. I'm open to changing a lot of the code, especially all the ugly stuff in the search-api, so please leave feedback!

It searches through all the docs and guides

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 26, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/5c8645ac6c49943aac2db9b1a597672c348d70bb/gradio-4.37.2-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@5c8645ac6c49943aac2db9b1a597672c348d70bb#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/5c8645ac6c49943aac2db9b1a597672c348d70bb/gradio-client-1.2.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 26, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
website patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Add search to website

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Just looked at the functionality and I think it works well @aliabd ! Sometimes the ranking of the matches was a bit off. For example, I'd expect the Oauth guide to be near the top when searching "oauth" but it's the sixth result. Something we can fix in v2 if it isn't an obvious fix.

image

@abidlabs abidlabs added the v: patch A change that requires a patch release label Jun 26, 2024
Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

Heck yeah @aliabd! Works super well in my tests

The only nit I have is: would it be possible to automatically select the first search result, so that you could press enter and it would navigate to that page without having to navigate down and select it?

@abidlabs
Copy link
Member

I thought I commented about this, but it seems to have disappeared: navigating to the right section in the page. For some searches, like "iframe" or "WaveformOptions", it would be great if it navigated to the right section in the page. Overall, not a huge pain point though.

@abidlabs
Copy link
Member

Ok so one thing I noticed is that when multiple items on a page match a given query, it only selects one of them to show in the search preview. That's fine, but we should prioritize headings over other items. For example, when I search "waveformoptions", I expect it will preview this part of the docs:

image

However, it shows the parameter instead:

image

and a user may completely miss the fact that there's a section dedicated to gr.WaveformOptions

Comment on lines +33 to +42
return results
.map((index) => pages[index as number])
.map(({ slug, title, content, type }) => {
return {
slug,
title: replace_text_with_marker(title, match),
content: get_matches(content, match),
type
};
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm getting a type error here locally (though the CI seems to pass lol)

Suggested change
return results
.map((index) => pages[index as number])
.map(({ slug, title, content, type }) => {
return {
slug,
title: replace_text_with_marker(title, match),
content: get_matches(content, match),
type
};
});
return results
.map((index: number) => pages[index as number])
.map(({ slug, title, content, type }: Page) => {
return {
slug,
title: replace_text_with_marker(title, match),
content: get_matches(content, match),
type
};
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

weird i get an error with your change:

Argument of type '(index: number) => Page' is not assignable to parameter of type '(value: Id, index: number, array: Id[]) => Page'.
  Types of parameters 'index' and 'value' are incompatible.
    Type 'Id' is not assignable to type 'number'.
      Type 'string' is not assignable to type 'number'.ts(2345)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but i don't see an error otherwise

@aliabd
Copy link
Collaborator Author

aliabd commented Jul 2, 2024

@freddyaboulton @abidlabs you're right that the ranking is a bit off. Maybe on v2 I can rank by # of occurrences on the page. I don't think prioritizing headers makes sense for how the code is structured right now, but will look into it. Navigating to the right spot would be killer imo but i definitely will need to rework how i'm generating the content database for that to work. Will do that in v2.

@abidlabs We can't autofocus the first result because it will take the cursor off the search box.

@hannahblair thanks for the changes! addressed all except for the one on search.ts

@abidlabs
Copy link
Member

abidlabs commented Jul 2, 2024

@abidlabs We can't autofocus the first result because it will take the cursor off the search box.

Not a big deal at all, but could pressing enter automatically go the first link?

@aliabd
Copy link
Collaborator Author

aliabd commented Jul 3, 2024

@abidlabs ok I made it work. First link is always in "focus" and pressing enter will go there, otherwise arrow down will move to the next link. Try it out and lmk what you think. I think it's pretty neat!

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

LGTM looks great to me @aliabd!

@aliabd aliabd merged commit ba59bb8 into main Jul 4, 2024
7 of 8 checks passed
@aliabd aliabd deleted the aliabd/docs-search branch July 4, 2024 04:57
@pngwn pngwn mentioned this pull request Jul 3, 2024
dawoodkhan82 pushed a commit that referenced this pull request Jul 10, 2024
dawoodkhan82 added a commit that referenced this pull request Jul 11, 2024
* latex fix

* format

* add changeset

* fix demo (#8696)

* Better spacing for codeblocks on docs (#8686)

* styling for codeblocks

* add changeset

* formatting

* add changeset

* changes

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Add search to website (#8624)

* Update action.yml (#8702)

* Model3D point cloud and wireframe display modes (#8687)

* display modes

* add changeset

* test fixes

* lint

* Update gradio/components/model3d.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* solid

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Fix playground to display errors (#8689)

* Fix the Playground on the website to trigger run_code() and install() with debounce and to display errors

* Remove an unused function, make_full_screen()

* Format demo/hello_world/run.py

* Update notebook

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* GRADIO_ALLOWED_PATHS & GRADIO_BLOCKED_PATHS comma separated environme… (#8705)

* GRADIO_ALLOWED_PATHS & GRADIO_BLOCKED_PATHS comma separated environment variables

* GRADIO_ALLOWED_PATHS & GRADIO_BLOCKED_PATHS comma separated environment variables

* add changeset

* Document GRADIO_ALLOWED_PATHS and GRADIO_BLOCKED_PATHS

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Ensure JS client `status_callback` functionality works and improve status messages (#8699)

* * bind handle_space_success
* ensure status callbacks work correctly

* add changeset

* test fixes + refactor

* tweak

* test

* Revert "test"

This reverts commit db1afc4.

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Documents auth in the guides, in the view API page, and also types the Blocks.config object  (#8720)

* auth docs

* changes

* add changeset

* add changeset

* add changeset

* type

* changes

* snippets

* import

* add changeset

* changes

* fix typing

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* remove on mount

* merge

* remove onmount

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
Co-authored-by: cocktailpeanut <121128867+cocktailpeanut@users.noreply.github.com>
Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmd + K doesn't work on lower resolutions of the docs site
5 participants