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

feat(v2): introduce DocSearch v3 search #2815

Merged
merged 38 commits into from
Jul 23, 2020

Conversation

francoischalifour
Copy link
Contributor

@francoischalifour francoischalifour commented May 27, 2020

Motivation

This PR integrates the new version of DocSearch, that better reflects what we think documentation search should be.

Closes #2808
Closes #2754

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Try the new search experience by clicking on the search button, or hitting ⌘ + K (or Ctrl + K): https://deploy-preview-2815--docusaurus-2.netlify.app.


Hello Docusaurus team! The DocSearch folks at @algolia have been working on a brand new DocSearch frontend the past months: DocSearch 3.

Context

Reducing users' efforts to get them started integrating your product is key to adoption. We created DocSearch in 2015 as a community effort to solve this problem.

We've had time to try different approaches since then and would like to propose you a new documentation search experience.

Features

This new DocSearch version offers a brand new user experience with two main UI components: a search button and a search modal. This new pattern allows more search features than the previous dropdown.

User experience (UX)

Modal search

We replaced the dropdown list for a modal. A modal makes the search experience more immersive, allows to support more search-related features (see below) and integrates better on mobile.

We offer a search button that opens the modal, as well a the Cmd + K keyboard shortcut.

Search button

image

Search modal

image

Mobile experience

DocSearch 3 was thought with mobile in mind. We've come as closed as we could to a native mobile experience:

  • Full-screen view.
  • Close virtual keyboard on scroll. Native search patterns blur the input when you start scrolling to give users more space to discover the results displayed behind the keyboard. DocSearch supports this feature out of the box.
  • Back to previous scroll position.
  • Selection search.

image

Recent searches

Users often need to jump back to content that they just previously searched. It can be quite annoying to type again what you just typed. We introduced recent searches:

image

Favorite searches

When you're learning a new framework or a new concept, you often need to come back multiple times to the same content. Users can now build their own start screen by adding searches to their favorites:

image

Selection search

What if you didn't have to type a query to search for content? A pattern that we believe would prove itself useful is Selection Search. This allows users to find more content related to your selection via DocSearch.

Select content, hit the search button (or click it on desktop):

selection-search

Search suggestions

Getting to a no results screen without indication can be frustrating. We now display search suggestions to jump back on main topics.

image

Offline detection

Not knowing why the search experience is loading endlessly or is not returning any results can be frustrating. We now detect when the search servers cannot answer and display data according to your network state.

image

We're investigating if offline search should be supported by DocSearch.

Dark mode

We support Docusaurus' dark mode:

Search button

image

Search modal

image

Color matching

The main colors are customizable via CSS variables for the DocSearch experience to match the Docusaurus websites.

Developer experience (DX)

React components

A recurring feedback from developers who implement DocSearch was the lack of React components. DocSearch has been rewritten in React and exposes React components now.

We'll base the vanilla JavaScript version on this React version with an alias to Preact.

Bundle size

Although this new version provides more features, the bundle is lightweight and compatible with lazy loading.

Lazy loading

Since we now export two components (search button and search modal) we can lazy load the modal to load the code only when needed.

This Docusaurus integration loads the modal code only when users are about the interact with the search: on the search button touch start on mobile and on hover on desktop.

What's next

We've been using this new DocSearch version on docsearch.algolia.com for a couple of weeks and a few users already expressed interest in this version.

Docusaurus is the first platform that we show this new version to. We consider this version as "beta" because it's a brand new direction that we've been reflecting on for over 3 years — we're open to your suggestions.

Once we roll it out to Docusaurus, we'll slowly roll it out to new DocSearch users.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 27, 2020
@s-pace
Copy link

s-pace commented May 27, 2020

Thank you for this PR @francoischalifour.

We will propagate the new crawler configuration for the v3 once this is merged :)

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented May 27, 2020

Deploy preview for docusaurus-2 ready!

Built with commit b42e7e5

https://deploy-preview-2815--docusaurus-2.netlify.app

@lex111 lex111 added status: don't merge yet This PR is completed, but we are still waiting for other things to be ready. pr: new feature This PR adds a new API or behavior. labels May 27, 2020
@lex111
Copy link
Contributor

lex111 commented May 27, 2020

It is very strange why there are so few results? https://v2.docusaurus.io/search?q=doc
It used to be >200 results.

@s-pace
Copy link

s-pace commented May 27, 2020

The crawl was on its way. Solved @lex111

@lex111 lex111 added this to the v2.0.0-alpha.57 milestone May 27, 2020
@krillboi
Copy link

@francoischalifour
Question about the "Favourites" feature. Does this save the favourites by writing to cookies? We have a very strict no cookies policy on our site and it would of course be sad to not be able to upgrade to this fantastic search as a result.

@francoischalifour
Copy link
Contributor Author

@krillboi Both Recent Searches and Favorite Searches use the localStorage API, not cookies. 🙂

@krillboi
Copy link

@francoischalifour Alright, I'm asking because of the infamous GDPR stuff, of which we try to avoid having a banner at all, but I'm not sure we can avoid having one when it saves information locally (both cookies and localstorage).

As a future request, perhaps having the ability to disable favourites/recent altogether could be an option :)

@Shipow
Copy link

Shipow commented May 28, 2020

Regarding the GDPR stuff I do believe the recent/favorites searches are acting like a shopping cart and no personal information are stored, we don't deal with identity of any kind. We'll obviously verify that but it seems that this category of use case doesn't require any banners/consentement. I'd be happy if you could double check that on your side too.

@swieczorek
Copy link

It would be great to have it merged, looking forward to it.

Good job 👍

Copy link
Contributor

@lex111 lex111 left a comment

Choose a reason for hiding this comment

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

First of all, I wanted to point out that this is a greatest improvement, I really like it, we will definitely include it in the upcoming Docusaurus release! But before that, we need to work on something to achieve an even better result.

  1. New search box in navbar catches the eye -- it stands out from all other UI elements of navbar. We don't need to focus on this particular element that way.

screenshot_15

I would make the background not so dark, rather the background from the current implementation is more suitable. In addition, I think it is necessary to reduce its height by analogy the current search input.

screenshot_14

BTW keyboard elements doesn’t look well on my Linux computer, eg, the text of “CTRL” is poorly read (see first screnshoot above).

Therefore, other keyboard elements in SVG look much clearer than if they are stylized using CSS. Maybe it makes sense to switch to use SVG icons in the search box too?

screenshot_19

In addition, in the dark mode, I believe that we also need to adopt the background from the current search.

New Old
image image

The shadow of the keyboard icons is pretty visible, maybe it reduce it?

  1. On small screens (eg iPhone 5), we see that the search navbar is positioned incorrectly. Earlier, in the previous release we did only display the search icon on mobiles, you can look at refactor(v2): show search icon only on mobiles #2791 for more details.

image

In this implementation search, I think we need to do the same. (Although in my opinion it looks worse than in the current version. Maybe the search in oval form looks better than a round one. Or the new magnifier icon is not very strong -- I'm not sure).

Issue on small mobiles Proposed solution
screenshot_12 screenshot_13
  1. Instead of a hard-coded magenta color, is it better for us to use the primary color website to style a new search?
Current behavior Proposed solution based on a website styling (by example of Docusaurus)
screenshot_18 screenshot_17
  1. Minor bugs:
  • The vertical scroll bar is displayed even if there is no scrollable content. Can we show it only when it is really needed?

screenshot_16


Also see my notes for lines of code below.

@Shipow
Copy link

Shipow commented May 29, 2020

Thanks a lot, very helpful and fair feedback @lex111, we are currently setting up a browser stack env to test on more configs. I also personally just switched to my PC to give more love to the UI there, it has been developed and fine tweaked mainly on macOS so far (small team, not enough diversity ^^). Do you have a browser and os compatibility list you'd like to cover with Docusaurus?

@lex111
Copy link
Contributor

lex111 commented May 29, 2020

There is a issue with not exactly accurate displaying the keyboard element of CTRL on all OS other than macOS, I suppose.

image

But it would be great to use SVG in navbar search, as it produces pretty clear font rendering.

Do you have a browser and os compatibility list you'd like to cover with Docusaurus?

We do not have much preference for this, we do not even support IE11, but just want to see smoothest and niceness UI.

@fishcharlie
Copy link

Why Command + K? I've never seen a search that uses that as the keyboard shortcut.

@yangshun
Copy link
Contributor

yangshun commented Jun 6, 2020

cmd + k is quite common actually, it's used in Messenger, Slack, Discord, Telegram, but more of searching for users. To focus on the search bar, the more common practice is to use /.

@slorber
Copy link
Collaborator

slorber commented Jul 22, 2020

thanks @francoischalifour

Can you add a little bit of doc in the Algolia plugin to explain how to sync the Docusaurus style to Algolia style?

Just a simple example, with a link to the github d2 website custom.css source file would likely be helpful for the users, as we won't do this sync automatically.

  • rebase :)

Copy link

@Shipow Shipow left a comment

Choose a reason for hiding this comment

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

LGTM, great work ^^

@slorber slorber removed the status: don't merge yet This PR is completed, but we are still waiting for other things to be ready. label Jul 23, 2020
@slorber
Copy link
Collaborator

slorber commented Jul 23, 2020

Unfortunately I don't see the styles being applied correctly in the deploy preview

image

@slorber
Copy link
Collaborator

slorber commented Jul 23, 2020

awesome, finally fixed this last weird linebreak issue 👍

we can merge now 🎊 thanks

@krillboi
Copy link

@krillboi has expressed the need to avoid using local storage: #2815 (comment)
Do we have an option that permits this? What should we say to users that want no local storage usage?

From @docsearch/react 1.0.0-alpha.23, you'll be able to bail out of Local Storage features (recent and favorite searches) with the option disableUserPersonalization that you can pass in the algolia field of your Docusaurus configuration.

@francoischalifour does this mean that the newly released Docusaurus 2.0.0-alpha.59 version supports this option?

@slorber
Copy link
Collaborator

slorber commented Jul 25, 2020

Yes it should work

@krillboi
Copy link

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search Keyboard Shortcut Algolia DocSearch Dark Mode