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

Option to return matched string

damianon opened this issue · comments

  • match-sorter version: 4.0.1
  • node version: 12.14.1
  • npm version: 6.11.3

Relevant code or config

type Category = {
    text: string;
    synonyms: string[];
}

 const sorted = matchSorter(
            categories,
            term,
            { keys: ['text', 'synonyms'], threshold: matchSorter.rankings.CONTAINS }
        );

What you did:
Search in multiple properties

What happened:
Returned whole matching objects

Problem description:
It's currenty not possible to know which string matched (either text, or one of the synonyms) and one would have to search each object again to find the one that matched.

Suggested solution:
Provide an option to also return the specific matching string. Not sure how this would be possible, as it uses the existing objects type as return type

Hi @damianon,

This is definitely something I have considered would be really nice to have, but with the way this library is currently implemented it would take a great deal of effort to do and so I think it's out of scope for this library.

Sorry.