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

Add CLOSE_MATCH threshold #21

Closed
kentcdodds opened this issue Sep 21, 2016 · 10 comments
Closed

Add CLOSE_MATCH threshold #21

kentcdodds opened this issue Sep 21, 2016 · 10 comments

Comments

@kentcdodds
Copy link
Owner

In my app, if the user types "India" they will see "Indonesia" because our threshold is set to MATCH. But this is confusing. I'd like to add a CLOSE_MATCH threshold which will function similar to MATCH but only count if there are only two characters between the previous letter and the next (so "Inda" would match "India" but not "Indonesia").

This threshold would probably go best between MATCHES and ACRONYM.

@kentcdodds
Copy link
Owner Author

Note: This could be a threshold, but also it could be used as a way to score how well things match. So maybe India and Indonesia will both match Ina, but because there are only 2 characters between n and a in India vs 6 characters in Indonesia, India would be sorted first.

@kevindavus
Copy link
Contributor

Would it be good to have a percent match and sort by that? So if the input is Ina that would be a 60% match with India and a 33%-44% match with Indonesia depending on if you count the n twice or not. So India would be at the top of the list.

@kentcdodds
Copy link
Owner Author

Hi @osfan501, thanks for your interest!

Interesting. This turns out to be a tough problem with there being two ns in Indonesia. Right now the implementation for match just goes one character at a time and counts the first instance. But if we're measuring distance between characters, we'd have to do something more fancy. I think that with our implementation we'd want to score it based on the closest distance between characters.

Also, we'd have to consider input like Ida where none of the characters are next to each other. In that scenario, we'd need to reduce the "closeness" to a single score. I'm not sure how the percentage would be calculated. But what if we just added up the number of characters between any given letter (based on the closest distance between characters) and sort by the lowest number.

This will be pretty complex.... :)

@kevindavus
Copy link
Contributor

So if I'm picturing this correctly for matching with Ida: India would have a score of 3 and Indonesia would have a score of 7.
My percentage idea was just the percentage of the characters that are present and didn't take positioning into consideration. I am interested in taking on this challenge!

kentcdodds pushed a commit that referenced this issue Nov 3, 2016
@kentcdodds
Copy link
Owner Author

Awesome! Make sure to follow the contributing guidelines (including the bit about adding yourself as a contributor).

Also, I created a skip test for this here. Just remove that line and run npm start test.watch (or npm start t.w) and make that test pass :)

Thanks!

@kevindavus
Copy link
Contributor

When I try to precommit getting this issue :

match-sorter@0.0.0-semantically-released precommit /Users/kevin/coding/match-sorter
opt --in pre-commit --exec "npm start validate"

match-sorter@0.0.0-semantically-released start /Users/kevin/coding/match-sorter
nps "validate"

nps executing: p-s -p lint,build,test && p-s test.build
nps executing: eslint .
nps executing: rimraf dist && p-s -p build.main,build.umd,build.umd.min
nps executing: jest --coverage
nps executing: babel --copy-files --out-dir dist/cjs --ignore *.test.js src
nps executing: rollup --config
nps executing: rollup --config --sourcemap --match-sorter-minify

RUNS src/index.test.js
process.argv.includes is not a function
TypeError: process.argv.includes is not a function
at Object. (/Users/kevin/coding/match-sorter/rollup.config.js:12:29)
at Module._compile (module.js:409:26)
at Object.require.extensions..js (/Users/kevin/coding/match-sorter/node_modules/rollup/bin/rollup:761:8)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at /Users/kevin/coding/match-sorter/node_modules/rollup/bin/rollup:768:19
at process._tickCallback (node.js:369:9)
at Function.Module.runMain (module.js:443:11)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki
process.argv.includes is not a function
TypeError: process.argv.includes is not a function
at Object. (/Users/kevin/coding/match-sorter/rollup.config.js:12:29)
at Module._compile (module.js:409:26)
at Object.require.extensions..js (/Users/kevin/coding/match-sorter/node_modules/rollup/bin/rollup:761:8)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at /Users/kevin/coding/match-sorter/node_modules/rollup/bin/rollup:768:19
at process._tickCallback (node.js:369:9)
at Function.Module.runMain (module.js:443:11)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki
The script called "build.umd.min" which runs "rollup --config --sourcemap --match-sorter-minify" failed with exit code 1 https://github.com/kentcdodds/p-s/blob/v3.0.3/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
src/index.js -> dist/cjs/index.js
The script called "build" which runs "rimraf dist && p-s -p build.main,build.umd PASS src/index.test.jsith exit code 1 https://github.com/kentcdodds/p-s/blob/v ✓ returns an empty array with a string that is too long (5ms)
✓ returns an empty array with a string that matches no items (2ms)
✓ returns the items that match (1ms)
✓ returns items that match in the best order (1ms)
✓ sorts equally ranking items in the same order in which they appeared in the original array
✓ no match for single character inputs that are not equal (1ms)
✓ can handle objects when specifying a key (2ms)
✓ can handle multiple keys specified (1ms)
✓ with multiple keys specified, all other things being equal, it prioritizes first keys first over index (1ms)
✓ can handle objected with nested keys (1ms)
✓ can handle property callback (1ms)
✓ can handle keys that are an array of values (1ms)
✓ when using arrays of values, when things are equal, the one with the higher index wins
✓ when providing a rank threshold of NO_MATCH, it returns all of the items (1ms)
✓ when providing a rank threshold of EQUAL, it returns only the items that are equal
✓ when providing a rank threshold of CASE_SENSITIVE_EQUAL, it returns only case-sensitive equal matches (1ms)
✓ when providing a rank threshold of WORD_STARTS_WITH, it returns only the items that are equal
✓ defaults to ignore diacritics (1ms)
✓ takes diacritics in account when keepDiacritics specified as true
✓ sorts items based on how closely they match (2ms)
○ WORD_STARTS_WITH will take camelCase, PascalCase, kebab-case, and snake_case into account

----------|----------|----------|----------|----------|----------------|

File % Stmts % Branch % Funcs % Lines Uncovered Lines
All files 100 100 100 100
index.js 100 100 100 100
---------- ---------- ---------- ---------- ---------- ----------------
Test Suites: 1 passed, 1 total
Tests: 1 skipped, 20 passed, 21 total
Snapshots: 0 total
Time: 0.927s, estimated 1s
Ran all test suites.
The script called "validate" which runs "p-s -p lint,build,test && p-s test.build" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.0.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code

npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/kevin/.nvm/versions/node/v4.4.4/bin/node" "/Users/kevin/.nvm/versions/node/v4.4.4/bin/npm" "start" "validate"
npm ERR! node v4.4.4
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! match-sorter@0.0.0-semantically-released start: nps "validate"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the match-sorter@0.0.0-semantically-released start script 'nps "validate"'.
npm ERR! This is most likely a problem with the match-sorter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nps "validate"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs match-sorter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls match-sorter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/kevin/coding/match-sorter/npm-debug.log

npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/kevin/.nvm/versions/node/v4.4.4/bin/node" "/Users/kevin/.nvm/versions/node/v4.4.4/bin/npm" "run" "precommit"
npm ERR! node v4.4.4
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! match-sorter@0.0.0-semantically-released precommit: opt --in pre-commit --exec "npm start validate"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the match-sorter@0.0.0-semantically-released precommit script 'opt --in pre-commit --exec "npm start validate"'.
npm ERR! This is most likely a problem with the match-sorter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! opt --in pre-commit --exec "npm start validate"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs match-sorter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls match-sorter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/kevin/coding/match-sorter/npm-debug.log

@kentcdodds
Copy link
Owner Author

Ah, this project requires Node v6 for development. You're using an older version and will need to upgrade. I'd that possible? I recommend https://git.io/nvm

@kevindavus
Copy link
Contributor

....whoops

@kevindavus
Copy link
Contributor

And now we can close this issue!

@kentcdodds
Copy link
Owner Author

Thanks!

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

No branches or pull requests

2 participants