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

Feature: search suggestions for search and quick launch #2775

Merged
merged 34 commits into from Feb 1, 2024

Conversation

Flo2410
Copy link
Contributor

@Flo2410 Flo2410 commented Jan 27, 2024

Proposed change

This PR adds search suggestions to the quick launch menu.
Currently, only the top four suggestions are shown, but it could be made adjustable in the config. I just wasn't sure where to put the setting. To the quick launch setting or the search widget?

Screenshot

image

Config

I added an option to the quicklaunch setting called hideSearchSuggestions which hides the suggestions.
Furthermore, I added the option suggestionUrl to the custom search widget.
This allows the user to set a custom URL for suggestions, like this:

- search:
    provider: custom
    url: https://www.ecosia.org/search?q=
    suggestionUrl: https://ac.ecosia.org/autocomplete?type=list&q=
    target: _blank

The body of the response from the API configured with suggestionUrl should have the following format:

[
  "home",
  [
    "home depot",
    "home depot near me",
    "home equity loan",
    "homeworkify",
    "homedepot.com",
    "homebase login",
    "home depot credit card",
    "home goods"
  ]
]

The first entry of the array contains the search query, the second one is an array of the suggestions.
In the example above, the search query was home.

The above example is also included in the change to the docs.

I found suggestion URLs for all implemented search providers and Ecosia which I used as an example for the custom provider.

Relates to #1225 and #1517

Type of change

  • New service widget
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation only
  • Other (please explain)

Checklist:

  • If applicable, I have added corresponding documentation changes.
  • If applicable, I have reviewed the feature and / or service widget guidelines.
  • I have checked that all code style checks pass using pre-commit hooks and linting checks.
  • If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.

If this feture and the search feature of the `quicklaunch` are turned on, up to *four* search suggestions will be shown as results.
This commit removes the async wrapper in the useEffect again. Instead the search suggestions are stored in their own state and the `quicklaunch` results show the last suggestions until they are updated.

This allows the search for services be fast even with a slow internet connection.
Now the search request is only sent, if the *searchString* changed.
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

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

Thanks. I can take a look at the PR later but this should be opt-in not opt-out, otherwise we’re going to get a lot of complaints about this showing up out of nowhere.

in that case presumably the variable should be renamed to show…

Also FYI our guidelines now require 10 up-votes for new features but I realize the docs don’t show that for the latest version yet

@shamoon

This comment was marked as outdated.

@shamoon shamoon closed this Jan 27, 2024
@shamoon

This comment was marked as outdated.

@shamoon shamoon reopened this Jan 28, 2024
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

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

It's also a bit odd that this works only for quick launch but comes from search. I think it should be implemented for both so they mirror each other. We'll need to make sure the UI for the search one is good.

src/pages/api/searchSuggestion.js Outdated Show resolved Hide resolved
src/pages/api/searchSuggestion.js Outdated Show resolved Hide resolved
docs/configs/settings.md Outdated Show resolved Hide resolved
src/components/quicklaunch.jsx Outdated Show resolved Hide resolved
src/components/quicklaunch.jsx Show resolved Hide resolved
src/components/widgets/search/search.jsx Outdated Show resolved Hide resolved
src/pages/index.jsx Outdated Show resolved Hide resolved
@shamoon shamoon marked this pull request as draft January 28, 2024 20:14
@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 28, 2024

Regrading the search in the search bar:

I made a quick implementation using the Combobox from headlessui.
It obviously still needs some work, but I would like some guidance regarding the design of the dropdown.

image

Furthermore, I would suggest moving the settings for the search provider, including the showSearchSuggestions setting, into a provider in the future. This probably would also enable the search function in the quick launch to work without having the search widget enabled. But this most likely falls out of the scope of this PR.

Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

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

Thanks for changes.

Yea the search widget auto-complete is a good start. As far as the design, it'd be easier if you push those changes and I can play with it, if youre OK with that.

And yea, maybe it seems overkill but users generally want more control especially as this is sending data (and getting tracked, of course) so I would include a setting for the widget (showSuggestions) in addition to the quick launch one. And I think something even better would be what we've done similarly elsewhere which is to let the search widget one act as the 'default' for quick launch (in other words if you set search widget showSuggestions to true, the quick launch will do the same unless you explicitly set it to false). If you only want them in quick launch set it just in quick launch. That feels 'clean' and means a lot of users will only need to set it in one place (if you want suggestions in search widget theres a good chance you do in QL).

src/pages/index.jsx Outdated Show resolved Hide resolved
src/components/quicklaunch.jsx Show resolved Hide resolved
shamoon and others added 2 commits January 28, 2024 16:41
This can be activated by adding `showSearchSuggestions: true` to the search widget config.
@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 29, 2024

I pushed the draft for the suggestions in the search bar.
You can activate them by adding showSearchSuggestions: true to the search widget config.

@shamoon shamoon enabled auto-merge (squash) January 30, 2024 20:42
@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 30, 2024

I think we are good here.
The only thing that bothers me is that the Google API doesn't return UTF-8 strings.

This makes the Google search suggestion API return charset=utf-8.
auto-merge was automatically disabled January 30, 2024 21:37

Head branch was pushed to by a user without write access

@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 30, 2024

I couldn't live with it. Looks like Google only returns UTF-8 if the User Agent includes Mozilla/5.0.

@shamoon shamoon enabled auto-merge (squash) January 30, 2024 23:47
@shamoon shamoon disabled auto-merge January 30, 2024 23:48
@shamoon shamoon enabled auto-merge (squash) January 30, 2024 23:48
@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 31, 2024

While writing the response above, I found some more bugs:

The first one is the Z-Index of the quick launch not being high enough:

image

The second one are unexpected line breaks because of the span elements for the suggestions.

image

The window width was 620px for the second screenshot.

@shamoon
Copy link
Collaborator

shamoon commented Jan 31, 2024

Thanks great catches! Should be fixed and I reverted the UA thing. Agree we can address in the future if needed, you ok with that?

Screenshot 2024-01-31 at 10 59 27 AM Screenshot 2024-01-31 at 10 41 07 AM

auto-merge was automatically disabled January 31, 2024 20:43

Head branch was pushed to by a user without write access

@Flo2410
Copy link
Contributor Author

Flo2410 commented Jan 31, 2024

I found another bug, I didn't URI encode the query again in the API route. This made it so that special characters were not correctly sent to the search suggestions API.

But apart from that, I think we are fine.

The thing with the Umlaut for Google doesn't bother me too much (I use DuckDuckGo anyway ;) )

While testing the Umlaut thing, I found another bug, but I will open an issue for that one.

Edit: Okay, I can't open an issue. How do I report a Bug? Or should I just open an PR?

@shamoon shamoon enabled auto-merge (squash) January 31, 2024 22:42
@shamoon
Copy link
Collaborator

shamoon commented Jan 31, 2024

How do I report a Bug?

You can open a discussion about it.

Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

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

Great work

@shamoon shamoon merged commit d5af7ed into gethomepage:main Feb 1, 2024
5 checks passed
discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 5, 2024
…2775)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 6, 2024
…2775)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 6, 2024
…2775)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
@Flo2410 Flo2410 deleted the feature-search-autocomplete branch February 8, 2024 17:32
Plancke pushed a commit to Plancke/homepage that referenced this pull request Feb 23, 2024
…2775)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Plancke pushed a commit to Plancke/homepage that referenced this pull request Feb 23, 2024
…2775)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion for related concerns. See our contributing guidelines for more details.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants