wire-elements / spotlight

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
MIT License
925 stars 72 forks source link

Add ability to define search synonyms #51

Closed dvanscott closed 2 years ago

dvanscott commented 2 years ago

I found myself wanting to provide some additional search terms to find one of my commands. My initial idea was to start putting those words in the description, but it ended up creating a really bad user experience with random words in the description that's displayed in the search results.

This PR adds the ability to add additional search terms (called synonyms here, but open to other ideas) to any command. This provides a simple way for developers to give their users additional terms to find commands.

For context, here's an example of how (and why) you might want to use synonyms for a command:

class ViewBillingSettings extends SpotlightCommand
{
    protected string $name = 'View Billing Settings';

    protected string $description = 'Update your billing settings';

    protected array $synonyms = [
        'subscription',
        'credit card',
        'payment',
    ];

    public function execute(Spotlight $spotlight): void
    {
        $spotlight->redirect('/settings/billing');
    }
}

This would allow for a user to type credit card and be show the View Billing Settings command in the search results.

dvanscott commented 2 years ago

@PhiloNL Pulled those out of the dependency search and updated the command stub. Should be all set!

PhiloNL commented 2 years ago

Thanks @dvanscott 🙌