krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.77k stars 754 forks source link

feat: allow to pass a getFn for a specific key #627

Closed fakenickels closed 2 years ago

fakenickels commented 2 years ago

This PR introduces the following

const fuse = new Fuse(Books, {
  useExtendedSearch: true,
  includeMatches: true,
  includeScore: true,
  threshold: 0.3,
  keys: [
    { name: "title", getFn: (book) => book.title },
    { name: "authorName", getFn: (book) => book.author.firstName },
  ],
});
const result = fuse.search({ title: "old man" });

I noticed it has been requested several times

Let me know if any other changes are necessary before merging

Aaronius commented 2 years ago

Yes please!

krisk commented 2 years ago

This is great. As a follow-up to this, could you create a PR with the relevant docs updates?

krisk commented 2 years ago

Could you make the requisite TS changes?