Git Product home page Git Product logo

fuzzy-search's People

Contributors

bendingbender avatar chinesedfan avatar dependabot[bot] avatar duzun avatar gfx avatar gheorghep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fuzzy-search's Issues

browser support?

Whats the browser support on this? I reckon that would be worth having in the docs too as its useful information.

Thanks

Allow sorting

Return the best match first

Calculate 'best match' on characters between matches

sort not ordering best (exact) matches on top

I'm using sort: true

I have an example where things aren't sorted as expected

search for 'board'
Results in order (searching these two fields):
'Alarm Dictionary', 'BO_ALARM_DICTIONARY'
'Dogmatix Board Replacements', 'DOGMATIX_BOARD_REPLACEMENT_V'

I would expect the row with "Board" in it to be ordered higher.

But instead, BO_ALARM_DICTIONARY ranks higher, maybe because B O A is close to the beginning of the string?

Not working with VueJS

Whenever I try to import this module into my VueJS / Nuxt Setup I encounter this error: render function or template not defined in component: anonymous
If I comment the import out the page renders normally.

Do you have any workaround?

In Node 10.x + Typescript using ts-node fuzzy-search fails when new'd

The output from ts-node REPL after importing the Parser and calling the search routine.

 var searcher = new fuzzy_search_1.default(this.registrations, ['name', 'realName', 'email', 'previousEmails', 'regCode'], {
                       ^

TypeError: fuzzy_search_1.default is not a constructor

The actual code is:

    searchRegistrations(needle: string) {
        const searcher = new FuzzySearch(this.registrations, ['name', 'realName', 'email', 'previousEmails', 'regCode'], {
            caseSensitive: false,
          });

          return searcher.search(needle)
    }

I dug around a bit and I can't find anything that I missed... this project looks amazing and was excited to find it. Hope its something simple we missed.

Thanks for the awesome project and the help!

Same letter issue

When using the same letter multiple times fuzzy search still returns it as a result.

bbbbbboat would match boat

Also add a test for this issue..

Numeric field search

Getting this error when searching on a numeric field:
TypeError: item.toLocaleLowerCase is not a function at Function.isMatch (app.d50f24c….js:3548) at FuzzySearch.search (app.d50f24c….js:3516) at VueComponent.activeData (app.d50f24c….js:3278) at Watcher.get (app.d50f24c….js:35120) at Watcher.evaluate (app.d50f24c….js:35220) at VueComponent.computedGetter [as activeData] (app.d50f24c….js:35446) at Object.get (app.d50f24c….js:34180) at Proxy.render (app.d50f24c….js:32297) at VueComponent.Vue._render (app.d50f24c….js:36241) at VueComponent.updateComponent (app.d50f24c….js:34811)

Highlight matching characters

I think that it would be great if we could highlight characters that triggered the match

search: somestring
result:
foosomestringbar
foosomethingStringbar

API could be something like this

const searcher = new FuzzySearch(people, ['name.firstName', 'state'], {
  caseSensitive: true,
  highlight: substring => colors.underline.bold(substring)
});

What do you think about such feature? I really miss something like this.

Advanced key matching?

This project to my understanding does two things: Searching object entries based on keys and then matching and scoring their corresponding values.

I've created a library called object-scan, which does solve the first part nicely (there is a lot to it). Would you be interested in a pull request?

When I started I thought object traverse and search was an easy problem. It is not. Hence it might be a good idea not to reinvent the wheel here ;) objext-scan is a dependency free package (which would fit with fuzzy-search) and has many, many tests.

Let me know what you think! Cheers, L~

Build fails with fuzzy-search

Hi,
In my react app the build getting failed with the fuzzy-search.

 Failed to minify the code from this file: 
./node_modules/fuzzy-search/src/FuzzySearch.js:3:15

It was working previously with the same react-scripts.

searching multiple keys at once

It'd be great if it (by default, or with an option) allowed a single search phrase to span multiple keys. For example, with:

[{name: 'The Adventures of Tom Sawyer', author: 'Mark Twain'}]

A search with keys ['name', 'author'] for 'tom mark' would return no results today, but I'd like for it to return the item in the array as a result.

I'm aware that I can create a compound key, but it'd be great if that were unnecessary. Thanks!

Fix travis ci

Tests are currently not running on travis. They are tested locally though!

fuzzy-search >= 2.2.0 does not compile on NodeJS

fuzzy-search v2.2.0 is no longer a universal JS:

$ node node_modules/fuzzy-search/dist/FuzzySearch.js
(...)

ReferenceError: window is not defined

As far as I see v2.1.0...v2.2.0 , upgrading build tool versions ( laravel-mix ?) may be related to this issue, I guess.

Not working with empty Arrays

Is it just me or did this lines somehow didn't make sense.

 constructor(haystack = [], keys = [], options = {}) {
    if (haystack.length === 0) {
      throw new Error('We need an array containing the search list');
    }

It looks like that it throws the error when the length of the haystack is 0 .. but the default is an empty Array. Also it can happen that the haystack is empty.

wouldn't it be better this way:

 constructor(haystack = [], keys = [], options = {}) {
    if (haystack.constructor !== Array) {
      throw new Error('We need an array containing the search list');
    }

Sort field does not work as expected

I'm writing a MIME Type dropdown box and using this for fuzzy searching, and the following code demonstrates that the "sort: true" option isn't pulling the best matches to the top:

new FuzzySearch(['application/cdfx+xml', 'application/pdf'], { sort: true }).search('pdf') === 'application/cdfx+xml'

Just to be clear, I would expect application/pdf to be the first result as it is an exact match

ESM and IE support

When building for browsers, the default behavior of Webpack when resolving package's main module is to look in package.json for these fields (in order):

  • browser: Browser-targeted module. Good to differentiate from Node targets.
  • module: Module using ESM syntax (discussion is in progress and stuff might change with Node 14)
  • main: Module using good-old CommonJS

https://webpack.js.org/configuration/resolve/#resolvemainfields

Also, it's very common to make babel-loader skip node_modules dir, to save some build time. Their own example instructs that.

https://github.com/babel/babel-loader#usage

FuzzySearch correctly points to a valid module, but that file not only contains ESM syntax, but lots of ES2015+ stuff.

Webpack handles ESM, but the other ES2015+ stuff passes straight through and IE does what it does best.

I suggest you to either:

  • Replace current module (or create a browser), with a ES5 module, keeping ESM declarations
  • Explain that the module webpack is going to use is not IE-ready and will require adjustments to support it. Here are a couple of possible fixes for their build config:
    • Force babel-loader to run in fuzzy-search directory;

      module: {
          rules: [
              {
                  test: /\.js$/,
                  include: ['src', 'node_modules/fuzzy-search'],
                  use: ['babel-loader'],
              },
          ],
      },
    • Create an alias, replacing fuzzy-search with a direct path to dist/FuzzySearch.js:

      resolve: {
          alias: {
              'fuzzy-search': 'fuzzy-search/dist/FuzzySearch',
          },
      },

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.