Code Monkey home page Code Monkey logo

Comments (5)

krisk avatar krisk commented on June 12, 2024

Could please elaborate? Thanks!

from fuse.

chaoaretasty avatar chaoaretasty commented on June 12, 2024

Sure.

Currently only Fuse itself is added to the globals but there are cases where the Searcher is useful in and of itself but there's no access to it. There are also occasions you might want to expose the actual score which currently gets eaten.

For example custom I've got a search function I think this could be a good fit with. It generates a score currently by a full text match on several fields with separate weightings (ie an item's relevance is 2x match(header) + 1x match(shortdescription) + 0.5x match(long description)). If Fuse's searcher was made public match could return the score rather than just 1 or 0.

from fuse.

krisk avatar krisk commented on June 12, 2024

Sounds good.

This should all be available with the latest release, as new options have been added. What you may be especially interested in is the ability to set the searchFn. Right now it defaults to BitapSearcher.

Additional options

// Fuse default options:
// Whether the score should be included in the result set.
// When <true>, each result in the list will be of the form: 
// `{ item: ..., score: ... }`
includeScore: false,

// Whether to sort the result list, by score
shouldSort: true,

// The search function to use
// Note that the default search function ([[Function]]) must 
// conform the following API:
//
//  @param pattern The pattern string to search
//  @param options The search option
//  [[Function]].constructor = function(pattern, options)
//
//  @param text: the string to search in for the pattern
//  @return Object in the form of:
//    - isMatch: boolean
//    - score: Int
//  [[Function]].prototype.search = function(text)
searchFn: BitapSearcher,

// The sort function to use
sortFn: function(a, b) {
  return a.score - b.score;
}

from fuse.

chaoaretasty avatar chaoaretasty commented on June 12, 2024

As long as it exposes the BitapSearcher without needing to use the other parts of Fuse that sounds great. (I love what Fuse does but for some of my use cases that bit gets in the way).

from fuse.

chaoaretasty avatar chaoaretasty commented on June 12, 2024

Thanks, done a quick test and I can get the searcher via var bitap = new Fuse.defaultOptions.searchFn(pattern, options)

Noticed a small bug though that prevents you doing this with null or undefined options. I'll send a pull request.

from fuse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.