Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key weighting - enhancement #62

Closed
andy-polhill opened this issue Oct 8, 2015 · 4 comments
Closed

Key weighting - enhancement #62

andy-polhill opened this issue Oct 8, 2015 · 4 comments
Labels

Comments

@andy-polhill
Copy link

Love the library so far, great work! One potential enhancement, (which if I find time I would love to do myself). Sometimes you want certain keys to have a stronger weighting. For example if you were searching for "Cheese" through the following library of books, you would maybe want "French Cheeses" to be your top match, however at the moment "101 Sandwiches" would take top billing due to a higher score in the description field.

[{
    "title": "French cheeses",
    "description": "Pictures and descriptions of all the cheeses France has to offer"
 }, {
    "title": "101 Sandwiches",
    "description": "Cheese, Ham, Pickle sandwich all the things"
}]

What I propose is an optional more advanced syntax for keys, where you provide some kind of modifier to that key making it less/more important than it's siblings. The final scoring could then be skewed via it's modifier.

keys = [{
  label: 'title',
  modifier: 1,
}, {
  label: 'description',
  modifier: 0.5,
}]
@krisk krisk added the feature label Nov 16, 2015
@krisk
Copy link
Owner

krisk commented Nov 16, 2015

I like this.

@ptz0n
Copy link

ptz0n commented Jan 1, 2016

Thanks for a great suggestion. Let's make it happen 👍

@krisk krisk closed this as completed Mar 2, 2016
@krisk krisk reopened this Mar 2, 2016
@krisk krisk closed this as completed in 8ffc08c Mar 2, 2016
@krisk
Copy link
Owner

krisk commented Mar 2, 2016

Implementation:

var fuse = new Fuse(books, {
  keys: [{
    name: 'title',
    weight: 0.3
  }, {
    name: 'author',
    weight: 0.7
  }],
});

Where 0 < weight <= 1

I published a new version: 2.1.0-beta. Let me know what you think.

Thanks!

krisk added a commit that referenced this issue Mar 7, 2016
@nickfun
Copy link

nickfun commented Aug 17, 2016

@krisk in your example, is title or author more heavily weighted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants