8000 Example of how to use in comparison · Issue #13 · words/double-metaphone · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Example of how to use in comparison #13

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

Open
mhkeller opened this issue Apr 1, 2025 · 1 comment
Open

Example of how to use in comparison #13

mhkeller opened this issue Apr 1, 2025 · 1 comment

Comments

@mhkeller
Copy link
mhkeller commented Apr 1, 2025

It would be helpful if the README included an example on how best to use this to match. My thought would be something like:

const word1 = 'Smith';
const word2 = 'Schmidt'; // These should match on one key

const keys1 = doubleMetaphone(word1); // Output: [ 'SM0', 'XMT' ]
const keys2 = doubleMetaphone(word2); // Output: [ 'XMT', 'SMT' ]

const isMatch = keys.some(k => keys2.includes(k));

Is that the best way?

One thought for an improvement would be the output of doubleMetaphone is a Set, in which case you could do this:

const isMatch = keys1.intersection(keys2).size > 0;

But it would be useful to create a benchmark to see if there is actually much of a performance improvement.

@wooorm
Copy link
Member
wooorm commented Apr 2, 2025

Hi Michael!

I kinda get it. But, there are other things that people want too, such as combining with stemmer as shown in the readme. And we can’t get examples for all cases. And at some point, perhaps it’s more about generic JavaScript knowledge and not about this package.

The problem with “Is that the best way?” is that there are different trade offs that apply to different people. To name some, compatibility with older JS vs performance vs bundle size.

The simplest one I can think of is:

const match = keys1[0] === keys2[0] || keys1[0] === keys2[1] || keys1[1] === keys2[0] || keys1[1] === keys2[1]

It should be the fastest and it has the best compatibility. I think GZip will also be fine on it: it likes repetition.

So, I dunno, yet.

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

No branches or pull requests

2 participants
0