kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript

Home Page:https://npm.im/match-sorter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opt out of certain checking

hozefaj opened this issue · comments

  • match-sorter: 2.2.0
  • node: v8.9.3
  • npm (or yarn) version: 5.7.1

Problem description:
Is there a way to opt out of certain checking. Like the use case I have, I do not want CASE ACRONYM, ACRONYM & SIMPLE MATCH being used for comparison. So any items that match these 3 things are omitted from final result.

This is not supported, but I'd happily accept a tested, documented, working PR for it 👍

Sure. Let me give it a shot. Will circle back in few days with a rough design.

I think this is the kind of API I'd like:

matchSorter(otherThings, 'app', {excludeRankings: [matchSorter.rankings.STRING_CASE_ACRONYM, matchSorter.rankings.ACRONYM, matchSorter.rankings.MATCHES]})

Though it just occurred to me that your purposes might be better served by simply doing:

matchSorter(otherThings, 'app', {threshold: matchSorter.rankings.CONTAINS})

This means that if it doesn't at least match well enough as the contains ranking then it wont be considered a match. Does that work for you?

Yup matchSorter(otherThings, 'app', {threshold: matchSorter.rankings.CONTAINS}) works perfectly.

I somehow was not able to make sense of what rankings meant. Your explanation here makes perfect sense.