krisk / Fuse

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

$and not returning what I would expect #640

Closed dwertheimer closed 2 years ago

dwertheimer commented 2 years ago

I'm sure I'm doing something simple wrong here. Can you please help me?

      const options = { keys: ['content'], includeScore: true, includeMatches: true, shouldSort: true }
      const notes = [
        {
          content: 'the lazy frog jumped over the log',
        },
        {
          content: 'the lazy dog jumped over the banana',
        },
        {
          content: 'the crazy man ate a frog',
        },
      ]
      const fuse = new Fuse(notes, options)
      const searchExp = { $and: [{ content: `=frog` }, { content: `=lazy` }] }
      const result = fuse.search(searchExp)
      expect(result.length).toEqual(1)

I expected that searchExp to return only one result (the first one, because it's the only one that contains bothfrog and lazy. But instead, it returns two (the first and third).

I have tried this expression in other forms (without the equals): const searchExp = { $and: [{ content: 'frog }, { content: 'lazy }] } //apostrophe, returns the same 2 results const searchExp = { $and: [{ content: frog }, { content: lazy }] } //no extended, returns all three (3) results I'm definitely missing something here. Can you please help me? Thank you! David

dwertheimer commented 2 years ago

Closing for now. I think I found a workaround. Thanks for this library!