How to use the match-sorter.rankings function in match-sorter

To help you get started, we’ve selected a few match-sorter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github acorn / twitter-bookmarks-search / content-script.js View on Github external
async function onSubmit(event) {
    event.preventDefault()
    if (!tweets && window.location.href.includes("mobile.twitter.com")) {
      return alert(
        `Shucks, you found that one little thing that doesn't work. You are on 'mobile.twitter.com' and it's not loading bookmarks for some reason. Change to 'twitter.com' and then it should work`
      )
    }

    if (!tweets) {
      return alert("Oh snap, no bookmarked tweets are loaded. Wait a little longer or reload to try again")
    }

    const query = event.target.elements[0].value
    const results = matchSorter(tweets, query, {
      keys: [
        { key: "full_text", threshold: matchSorter.rankings.ACRONYM },
        { key: "user.screen_name", threshold: matchSorter.rankings.ACRONYM },
        { key: "user.name", threshold: matchSorter.rankings.ACRONYM },
      ],
      keepDiacritics: true,
    })
    // console.log("Bookmark search results", results)
    setResults(results)
  }
github acorn / twitter-bookmarks-search / content-script.js View on Github external
if (!tweets && window.location.href.includes("mobile.twitter.com")) {
      return alert(
        `Shucks, you found that one little thing that doesn't work. You are on 'mobile.twitter.com' and it's not loading bookmarks for some reason. Change to 'twitter.com' and then it should work`
      )
    }

    if (!tweets) {
      return alert("Oh snap, no bookmarked tweets are loaded. Wait a little longer or reload to try again")
    }

    const query = event.target.elements[0].value
    const results = matchSorter(tweets, query, {
      keys: [
        { key: "full_text", threshold: matchSorter.rankings.ACRONYM },
        { key: "user.screen_name", threshold: matchSorter.rankings.ACRONYM },
        { key: "user.name", threshold: matchSorter.rankings.ACRONYM },
      ],
      keepDiacritics: true,
    })
    // console.log("Bookmark search results", results)
    setResults(results)
  }
github learn-anything / learn-anything / src / pages / index.js View on Github external
);

  // this will be the same every time and because this re-renders on every
  // keystroke I'm pretty sure useMemo is appropriate here.
  const topics = React.useMemo(() => {
    return result.data.topics.map(e => ({
      name: e.name,
    }));
  }, [result.data.topics]);

  const [search, setSearch] = React.useState("");
  const searchInputRef = React.useRef();
  const filteredTopics = matchSorter(topics, search, {
    keys: [
      // "name",
      { key: "name", threshold: matchSorter.rankings.CONTAINS },
    ],
  });

  return (
    <div style="{{">
      <div>
        <label>Search Topics: </label>
        <input id="search-input"> setSearch(searchInputRef.current.value), {
            wait: 200,
          })}
          type="search"
          autoFocus
        /&gt;</div></div>
github uber / react-vis / www / src / screens / search.js View on Github external
// keystroke I'm pretty sure useMemo is appropriate here.
  const blogposts = React.useMemo(() =&gt; {
    return result.blogposts.edges.map(e =&gt; ({
      ...e.node.fields,
      excerpt: e.node.excerpt,
    }))
  }, [result.blogposts.edges])

  const [search, setSearch] = React.useState('')
  const searchInputRef = React.useRef()
  const filteredBlogPosts = matchSorter(blogposts, search, {
    keys: [
      'title',
      'categories',
      'keywords',
      {key: 'description', threshold: matchSorter.rankings.CONTAINS},
      {key: 'excerpt', threshold: matchSorter.rankings.CONTAINS},
    ],
  })

  return (
    <div>
      <div>
        <h1>Search Kent C. Dodds Blogposts</h1>
      </div>
      <small>
        {`If you can't find what you're looking for with this, try `}
        <a href="https://www.google.com/search?q=site%3Areact-vis.com%2Fblog+testing">
          using Google
        </a>
        {'.'}
      </small></div>
github kentcdodds / react-github-profile / src / screens / user / components / repo-list.js View on Github external
function RepoList({repos, filter}) {
  const matchingRepos = matchSorter(repos, filter, {
    keys: [
      'name',
      {maxRanking: matchSorter.rankings.SIMPLE_MATCH, key: 'language'},
      {maxRanking: matchSorter.rankings.CONTAINS, key: 'description'},
    ],
  })
  return (
    <ul>
      {matchingRepos.map(repo =&gt; (
        
      ))}
    </ul>
  )
github ifiokjr / remirror / @remirror / extension-emoji / src / emoji-utils.ts View on Github external
export const sortEmojiMatches = (query: string, maxResults = -1) => {
  const results = matchSorter(emojiList, query, {
    keys: ['name', item => item.description.replace(/[^\w]/g, '')],
    threshold: matchSorter.rankings.CONTAINS,
  });

  return take(results, maxResults);
};
github kentcdodds / react-github-profile / src / screens / user / components / repo-list.js View on Github external
function RepoList({repos, filter}) {
  const matchingRepos = matchSorter(repos, filter, {
    keys: [
      'name',
      {maxRanking: matchSorter.rankings.SIMPLE_MATCH, key: 'language'},
      {maxRanking: matchSorter.rankings.CONTAINS, key: 'description'},
    ],
  })
  return (
    <ul>
      {matchingRepos.map(repo =&gt; (
        
      ))}
    </ul>
github code-mancers / interceptor / app / components / RequestList.tsx View on Github external
filterMethod: (filter: any, rows: any) => {
        return matchSorter(rows, filter.value, {
          keys: ["url"],
          threshold: matchSorter.rankings.CONTAINS
        });
      },
      filterAll: true
github uber / react-vis / www / src / screens / search.js View on Github external
const blogposts = React.useMemo(() =&gt; {
    return result.blogposts.edges.map(e =&gt; ({
      ...e.node.fields,
      excerpt: e.node.excerpt,
    }))
  }, [result.blogposts.edges])

  const [search, setSearch] = React.useState('')
  const searchInputRef = React.useRef()
  const filteredBlogPosts = matchSorter(blogposts, search, {
    keys: [
      'title',
      'categories',
      'keywords',
      {key: 'description', threshold: matchSorter.rankings.CONTAINS},
      {key: 'excerpt', threshold: matchSorter.rankings.CONTAINS},
    ],
  })

  return (
    <div>
      <div>
        <h1>Search Kent C. Dodds Blogposts</h1>
      </div>
      <small>
        {`If you can't find what you're looking for with this, try `}
        <a href="https://www.google.com/search?q=site%3Areact-vis.com%2Fblog+testing">
          using Google
        </a>
        {'.'}
      </small>
      <div></div></div>

match-sorter

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

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis