Skip to content

Add ability to define search synonyms - #51

Merged
PhiloNL merged 14 commits into
wire-elements:masterfrom
dvanscott:master
Nov 6, 2021
Merged

PhiloNL merged 14 commits into
wire-elements:masterfrom
dvanscott:master

Conversation

@dvanscott

Copy link
Copy Markdown
Contributor

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.

@PhiloNL PhiloNL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR looks like a great addition! 🙌
Just one question about one of the Fuse instances, other than that everything seems good to go. 😄

Comment thread resources/js/spotlight.js Outdated
this.commandSearch = new Fuse(this.commands, {threshold: 0.3, keys: ['name', 'description']});
this.dependencySearch = new Fuse([], {threshold: 0.3, keys: ['name', 'description']});
this.commandSearch = new Fuse(this.commands, {threshold: 0.3, keys: ['name', 'description', 'synonyms']});
this.dependencySearch = new Fuse([], {threshold: 0.3, keys: ['name', 'description', 'synonyms']});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the synonyms apply for the dependencies or did you ran into issues if you did not apply the synonyms properties for both Fuse instances?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@PhiloNL I wasn't quite sure if they needed to be added there are not. Now that I think about it, you're probably right that they don't need to be there. Let me just run a couple of tests and if everything checks out, I'll push an update.

@dvanscott

Copy link
Copy Markdown
Contributor Author

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

@PhiloNL
PhiloNL merged commit 9961193 into wire-elements:master Nov 6, 2021
@PhiloNL

PhiloNL commented Nov 6, 2021

Copy link
Copy Markdown
Contributor

Thanks @dvanscott 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants