krisk / Fuse

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

Logical Query Operators with simple search string input #741

Closed marceloverdijk closed 3 months ago

marceloverdijk commented 8 months ago

Is there an existing issue for this?

Your question

Having a list like:

[
  {
    "title": "Old Man's War",
    "author": {
      "first.name": "John",
      "last.name": "Scalzi",
      "age": "61"
    }
  }
]

with the config:

const options = {
  useExtendedSearch: true,
  includeScore: true,
  keys: [
    'title',
    ['author', 'first.name'],
    ['author', 'last.name'],
    'author.age'
  ]
}

logical query operations with extended-search can be used like:

const result = fuse.search({
  $and: [
    { title: 'old war' }, // Fuzzy "old war"
    {
      $path: ['author.age'],
      $val: "'61" // Exact match for age
    },
  ]
})

or with $or like:

const result = fuse.search({
  $or: [
    { title: 'old war' }, // Fuzzy "old war"
    {
      $path: ['author.age'],
      $val: "'61" // Exact match for age
    },
  ]
})

Now I wonder if Fuse could support the same but with a "simple" query like:

const result = fuse.search("title='old war' author.age='61") // fuzzy search on title field *and* exact match on age

const result = fuse.search("title='old war' | author.age='61") // fuzzy search on title field *or* exact match on age

const result = fuse.search("'old war' author.age='61") // general fuzzy search *and* exact match on age

Of course I could parse above query string in the appropriate logical query operators object as input for the search, but I wonder if somebody already did something like that, or if this would be interesting for Fuse itself?

I also noticed the last release was quite some time ago, so I wonder if new features are still considered for this project?

krisk commented 8 months ago

I admittedly have taken a bit of break, given there's been lots of things going on, but I'm trying to get back to regular updates. As far as this features is concerned, it is an interesting one. Let me try to spend some time this weekend on this. Thanks!

marceloverdijk commented 8 months ago

Thx for the update Kiro. Hope all is well. There is absolutely no hurry, but it indeed is an interesting feature. It could provide a quite interesting "query language" with exact, fuzzy search etc.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days