Skip to content
Discussion options

You must be logged in to vote

Looking at this again, my earlier suggestion wasn't great for this use case — this is really a numeric distance/nearest-neighbor problem, not a text search one. Fuse operates on string matching, so it's not the right tool for comparing numeric attribute vectors.

For this kind of thing, you'd want to compute something like Euclidean distance between the query object and each job, then sort by that. A simple approach:

const query = { people: 8, physical: 1, mental: 7, location: 6, money: 5, value: 4 }
const keys = Object.keys(query)

const sorted = jobs
  .map(job => ({
    item: job,
    distance: Math.sqrt(keys.reduce((sum, k) => sum + (job[k] - query[k]) ** 2, 0))
  }))
  .sort((a, b) => a.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by krisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants