ajitid / fzf-for-js

Do fuzzy matching using FZF algorithm in JavaScript
https://fzf.netlify.app
BSD 3-Clause "New" or "Revised" License
887 stars 21 forks source link

Search across multiple item properties #86

Open caschbre opened 3 years ago

caschbre commented 3 years ago

Is your feature request related to a problem? Please describe. I've been looking for a replacement to fuse.js and came across this library. I use fzf all over my OS and like the speed and results it produces. This nearly replaces all of the features I currently use on fuse.js except for one key aspect. The ability to have weighted search across multiple item properties. You can see a fusejs example here. I think right now my only option is to use the non-string selector feature by concatenating the properties. That can get messy though if all of the properties are not simple terms/words... and I'm not sure how that would affect scoring.

An example usage could be searching calendar events that include an event title, name of the host, names of all the participants, and a short description.

{
  title: 'Learn how to fzf!',
  host: 'Ajit',
  participants: ['Craig', 'John', 'Bill'],
  description: 'How to use fzf on your OS, in vim, and now in JS!',
}

Describe the solution you'd like A possible solution without weighting the item properties might be to search and score each searchable property. And then calculate a single score for the item. Some simple (configurable) item scoring calculates could be total score, average score, or highest score. And then if anyone wanted to hook into the scoring algorithm they could implement a weighted scoring algo.

Describe alternatives you've considered After searching for fusejs alternatives, fzf is the one I chose to dive into first so I haven't looked hard at other fuzzy search/sort libraries. And the only alternative within fzf that I've found is the concatenating properties in the selector.

ajitid commented 3 years ago

I haven't looked hard at other fuzzy search/sort libraries.

If your requirement is immediate, I would suggest you to look into match-sorter and fuzzysort.

This is certainly one of the things I have in my mind to work upon. Honestly, I haven't had a chance to look into how others have implemented it, probably now is the time. 😅

ajitid commented 3 years ago

Hey @caschbre! It seems that in both match-sorter and fuzzysort one cannot search in multiple fields at once. So in the example that you've given above, searching for "how to fzf ajit" won't give any result. Does this matches to the result that you are expecting?

caschbre commented 3 years ago

@ajitid I have not had a chance to try either one out yet. We're currently using fusejs which handles multiple fields, but I've been looking for something that performs better (speed and accuracy) and is easier to customize.

I briefly looked over the two libraries you mentioned and I believe that match-sorter does search across multiple fields by configuring the 'keys'. Also see https://github.com/kentcdodds/match-sorter#match-many-words-across-multiple-fields-table-filtering.

ajitid commented 1 year ago

For others stumbling upon this issue, I'm not planning to work on this. I did clone the approach that match-sorter does (which @/caschbre mentioned just above), but that didn't feel right.

However I'll happily accept a PR which solves this properly. I've already put a 'help-wanted' label an year ago. Am I'm commenting now just to clarify it. If you think you can help but have questions on parts of the code, create a new issue and put those questions there, and I'll reply back to you. Thanks.