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

More threshold examples #55

Closed
chapmanjacobd opened this issue Mar 21, 2019 · 1 comment
Closed

More threshold examples #55

chapmanjacobd opened this issue Mar 21, 2019 · 1 comment

Comments

@chapmanjacobd
Copy link

I'm not sure if this is possible with the threshold option but I'm looking to prioritize when l = false as the most important key to sort on. so results with l = false will be at the top of the results

Relevant code or config:

function getSuggestions(value, results) {
  const inputValue = deburr(value.trim()).toLowerCase();
  const inputLength = inputValue.length;
  let count = 0;
  console.log(results);
  const tmp = [];
  for (let j = 0; j < 2; j++) {
    for (let k = 0; k < results.length; k++) {
      if (results[k].l == (j == 0 ? false : true)) {
        tmp.push(results[k]);
      }
    }
  }
  results = tmp;
  const getItems = value =>
    value
      ? matchSorter(results, value, {
          keys: ["i", "n", "nl_n", "s", "nl_s", "c", "nl_c"],
        })
      : results;

  return inputLength === 0
    ? []
    : getItems(inputValue).filter(() => {
        // put the city data here.
        const keep = count < 8;

        if (keep) {
          count += 1;
        }
        // console.log(keep)
        return keep;
      });
}

I can't figure out a way to put l as a key. I tried using different thresholds but I couldn't wrap my head around the threshold options

@kentcdodds
Copy link
Owner

I don't think that this is possible with match-sorter by itself. You may need to group the array into two unique arrays which have l = false and those which do not, then run match sorter for each and then combine them with the l = false group first.

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