krisk / Fuse

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

Add an option with dictionary of synonyms #698

Closed mirorac closed 1 year ago

mirorac commented 1 year ago

Description

Synonyms are words that are considered equal to its associated word for the purposes of calculating search results.

Describe the solution you'd like

Add synonyms option object that can contain words and their respective synonyms.

const list = ["Old Man's War", "The Lock Artist"]
const options = {
  synonyms: {
    artist: ['composer', 'maestro']
  }
}
const fuse = new Fuse(list, options)

fuse.search('composer') // result: ['The Lock Artist']
fuse.search('cmposer') // result: ['The Lock Artist']
fuse.search('maestro') // result: ['The Lock Artist']
fuse.search('artist') // result: ['The Lock Artist']

Describe alternatives you've considered

Add an array of synonyms to each item in the list. However, this way neglects the token location, context, etc...

const list = [
  {
    string: "Old Man's War",
    synonyms: [],
  },
  {
    string: "The Lock Artist",
    synonyms: ['composer', 'maestro']
  }
]
ShahriarKh commented 1 year ago

This will be a great feature, especially for multi-language contexts. I think, it will be better if the "synonyms" is added as a search option, and not directly on data; for cases when the data is loaded from a remote source.

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