krisk / Fuse

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

Recommended way to boost based on a different field #754

Closed amir20 closed 3 weeks ago

amir20 commented 5 months ago

Is there an existing issue for this?

Your question

Hello,

I think the closest issue I could find to this is https://github.com/krisk/Fuse/issues/444. So I'd like to know if I am thinking about this the right way.

I use fuse.js for Dozzle where I show Docker logs. In the UI, users are able to search containers by name. So for example, data might look like

const data = [
  {name: "foo bar", running: true},
  {name: "foo bar", running: false},
  {name: "test", running: true},
  ...
]

When searching for foo I want containers that are running to be on top.

Currently, I do a custom sort after getting back the results from fuse. However, this is not super efficient because I have to receive more results than needed to do a proper sort.

But I wonder if there is a better way. I am familiar with Ellasticsearch and lucene. In those frameworks, I could do something like $query || ($query && running:true)^2) where I am essentially boosting a second query to be at top.

What's the best way to achieve this?

Here are some ideas:

  1. Sort post search like I do now
  2. Use logical queries, but I am not sure how that would be possible because I don't want to specify every single field.
  3. Use an example like https://github.com/krisk/Fuse/issues/444 and "boost" weight and resort

Any recommendation would be appreciated. Thank you!

github-actions[bot] commented 1 month 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