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

[RFC] Extended searching in v4.0.0-beta #356

Closed
krisk opened this issue Mar 10, 2020 · 3 comments
Closed

[RFC] Extended searching in v4.0.0-beta #356

krisk opened this issue Mar 10, 2020 · 3 comments

Comments

@krisk
Copy link
Owner

krisk commented Mar 10, 2020

I recently added extended search (inspired by fzf). I'd love our thoughts 🙏

Why?

This form of advanced searching allows the user to fine-tune their results. It can be used to immediately exclude a large part of their search body before doing the final fuzzy matching. It's reminiscent of Unix-like terminal commands.

Search syntax

Fuse.js will work exactly as before, and if you give the option useExtendedSearch:true, you can use the following syntax in the search query:

Token Match type Description
jscript fuzzy-match Items that match jscript
'python exact-match Items that include python
!ruby inverse-exact-match Items that do not include ruby
^java prefix-exact-match Items that start with java
!^earlang inverse-prefix-exact-match Items that do not start with earlang
.js$ suffix-exact-match Items that end with .js
!.go$ inverse-suffix-exact-match Items that do not end with .go

White space acts as an AND operator, while a single pipe (|) character acts as an OR operator.

For example, this search query:

"^core go$ | js$ | py$ xy$"

is interpreted as the following logical expression:

("^core" AND "go$") OR "js$" OR ("py$" AND "xy$")

Usage

const options = {
  // Enable extended search
  useExtendedSearch: true,
  keys: [
    /*...*/
  ],
}

const fuse = new Fuse(/*...*/)
fuse.search('^jscript .python$ | ruby | !java')

Do we still need the previous implementation of tokenization (i.e, see #355)? With extended search, we have more useful form of fuzzy tokenization, where you could provide a pipe-delimited search query:

fuse.search("jcript | pthon | rby")

Feedback? Questions?

Please have a go at it 😄

@KWierso
Copy link

KWierso commented Mar 10, 2020

This looks great, and almost exactly what I was wanting when I filed #306!

I'm no longer directly affiliated with the project that was using Fuse that would have benefited from this, but I can probably whip up a pull request for them to switch to this and see how it actually works in real usage.

@KWierso
Copy link

KWierso commented Mar 10, 2020

Works great, too!

@krisk
Copy link
Owner Author

krisk commented Mar 16, 2020

Now in the latest beta (actually v5)

@krisk krisk closed this as completed Mar 16, 2020
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