pulsar-edit / package-backend

Pulsar Server Backend for Packages
https://api.pulsar-edit.dev
MIT License
12 stars 11 forks source link

Better search term handling #107

Closed confused-Techie closed 1 year ago

confused-Techie commented 1 year ago

Requirements

Description of the Change

This PR came about while working on much larger changes to how we handle search. But discovering this trick, was so simple and small I thought it'd only be smart to try and push it out much earlier than the other branch ends up being completed.

This PR simply changes how we handle user input during a search to allow search to be more intuitive.

For the below examples we will assume the user has typed "Language HTML".

Currently when a user provides their search a few things happen to the search term.

Then during the search we supply the following to the DB %searchTerm%, which with our example would look like %language html%.

Adding % means to allow anything before. So this current search would match: this-is-my-super-cool-language htmlProject

But it wouldn't match language-html because there is no dash.

So what this PR does is replace a collection of wordSeparators with _, which when searching on the DB means any single character.

All the stop words we filter currently are:

This means any of those will be converted to _. So with our previous example will now be %language_html%

Which this will now match:

So this is an obvious improvement, the only downside is that it will not match languagehtml, but considering we already won't match that, it's not a downside so much as still room for improvement.