WebDevStudios / wp-search-with-algolia

Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance.
https://wordpress.org/plugins/wp-search-with-algolia/
138 stars 54 forks source link

This there a way to add recent searches to autocomplete #420

Open mattc-poolwarehouse opened 1 month ago

mattc-poolwarehouse commented 1 month ago

I was wondering if there is a way to show the recent searches a user has made. There is documentation on the Algolia docs on how to do this, but I'm not sure how to implement this in the way that this plugin sets up autocomplete. They use the createLocalStorageRecentSearchesPlugin in the algolia library.

https://www.algolia.com/doc/ui-libraries/autocomplete/guides/adding-recent-searches/

Anyone else implemented this feature?

tw2113 commented 1 month ago

Hi @mattc-poolwarehouse

TLDR: this is mostly just an informational reply about current status about what's shipped by default and in-the-works changes.

We fully admit that at the moment we still have the 0.38.x version of autocomplete as the default setup/template out of box, but haven't fully attempted to do an update yet to allow for choosing version 1.x.

The biggest hurdle is that we can't necessarily accurately target the search field any more since 1.x Autocomplete expects a container provided as such: <div id="autocomplete"></div> and they handle the rest. This requires users to intentionally create where that div goes, most likely replacing the search field that was originally there. Hopefully you can see how that'd be a small trouble spot for out of box functionality.

That said, we do have a branch of the plugin that is meant to offer the ability to choose what we call "legacy" vs "modern" in terms of intended UI changes.

You can see the autocomplete.php template that that would ship with, over at https://github.com/WebDevStudios/wp-search-with-algolia/blob/feature/272-autocomplete-upgrade/templates/autocomplete-modern.php

That said, just making use of that as a starter won't necessarily get you all the way through, as you'd still need to implement and load the newer Autocomplete libraries as well.

That said, I'm definitely curious how ready the branch is overall, outside of the div placement. Last I checked, I am using it on a personal site without much issue, but it also gets zero traffic outside of myself :D

Whole branch if curious https://github.com/WebDevStudios/wp-search-with-algolia/tree/feature/272-autocomplete-upgrade

mattc-poolwarehouse commented 1 month ago

Michael, Thanks for the quick response. Looking at the autocomplete-modern.php template, it does look like the code in the link I sent. I'll try pulling that branch down to a test environment and playing with it. Thanks again!

tw2113 commented 1 month ago

For what it's worth, you'll most likely need to run things like npm install and similar, as the repo here isn't immediately the same overall files as compared with what you get at https://wordpress.org/plugins/wp-search-with-algolia/.