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

feat(variables): added arrayFuzzySearch variable (#3002) #3003

Open
wants to merge 10 commits into
base: v5
Choose a base branch
from

Conversation

Oceanity
Copy link
Contributor

Description of the Change

Introduced an arrayFuzzySearch variable that allows a user to find the closest match in an array for a provided search

Applicable Issues

#3002

Testing

Tested all 3 provided examples to ensure they work as expected, and also tested passing in a simple custom variable array and an array from an HTTP Request response

Screenshots

n/a

Introduced an `arrayFuzzySearch` replace variable
@Oceanity Oceanity requested a review from ebiggz as a code owner February 18, 2025 05:08
@Oceanity Oceanity changed the base branch from master to v5 February 18, 2025 05:08
Checked out `package-lock.json` from Upstream as it should not be effected by my changes
@phroggster
Copy link
Collaborator

Thanks Oceanity, I love this! If only everything in computer sciences were fuzzier by default, we'd all be better off!

Two (non-blocking) ideas:

  • An optional minimumSimilarity argument. Where, if specified, the variable evaluation would return the default value ("null", or see below) should the match with the smallest distance be greater than the argument's numeric-ish value.
  • An optional defaultValue argument, in similar style to $userMetadata[...] or $customVariable[...], so that we can confidently match viewer-supplied text against an (admittedly esoteric) array consisting of, e.g. ["null", "mull", "bull"].

To future reviewer(s) of this:
Fuse.js released version 7.1.0 ~2 weeks ago. It adds the ability to optionally ignore diacritic (the fancy little "hats" that some letters can wear in many languages outside of English) character differences. IMHO, the fuse.js dep should get bumped to 7.1.0 to support this feature, and we should all embrace the fuzzy.

Added support for Fuse.js's `threshold` property as well as the ability to supply a default value if no matches are found crowbartools#3003 (comment)
@Oceanity
Copy link
Contributor Author

Thanks Oceanity, I love this! If only everything in computer sciences were fuzzier by default, we'd all be better off!

Two (non-blocking) ideas:

* An optional `minimumSimilarity` argument. Where, if specified, the variable evaluation would return the default value ("null", or see below) should the match with the smallest distance be greater than the argument's numeric-ish value.

* An optional `defaultValue` argument, in similar style to `$userMetadata[...]` or `$customVariable[...]`, so that we can confidently match viewer-supplied text against an (admittedly esoteric) array consisting of, e.g. `["null", "mull", "bull"]`.

To future reviewer(s) of this: Fuse.js released version 7.1.0 ~2 weeks ago. It adds the ability to optionally ignore diacritic (the fancy little "hats" that some letters can wear in many languages outside of English) character differences. IMHO, the fuse.js dep should get bumped to 7.1.0 to support this feature, and we should all embrace the fuzzy.

Added in da8c8fa

Copy link
Member

@ebiggz ebiggz 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 working on this @Oceanity!

I agree with @phroggster that it would be worth updating fuse.js to latest. We are already on 7.x.x and from the change log I am not seeing any notable breaking changes. If you could bump fuses version in this PR, that would be great. Then we can get this merged in 👌🏻

Upgraded Fuse.js dependency to have access to new functionality
Utilized the ignoreDiacritics param in Fuse.js 7.1.0 to allow the replace variable to ignore diacritics
@Oceanity
Copy link
Contributor Author

Thanks for working on this @Oceanity!

I agree with @phroggster that it would be worth updating fuse.js to latest. We are already on 7.x.x and from the change log I am not seeing any notable breaking changes. If you could bump fuses version in this PR, that would be great. Then we can get this merged in 👌🏻

Updated Fuse.js to latest (d31ad98) and added param to ignore Diacritics (8ee0ba2)!

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