Giter Club home page Giter Club logo

fzearch's Introduction

Fzeach

Fzearch is a fuzzy search library for Javascript/Typescript. It is base on Smith-Waterman algorithm and provides a simple and easy-to-use API for fuzzy search.

How to use

import { Fzeach } from 'fzeach';

const fzeach = new Fzeach();

const list = [
	'apple',
	'banana',
	'orange',
	'grape',
	'kiwi',
	'mango',
	'melon',
	'peach',
	'pear',
	'plum',
	'strawberry',
	'watermelon',
];

const keyword = 'apple';

// create a class instance
const result = fzeach.search(list, keyword, 'levenshtein');
// or use the static method
const result = Fzeach.search(list, keyword, 'damerau-levenshtein');

API

Fzearch.search(query: string, db: string[], options?: FzearchOptions): any[]

  • query: The keyword to search.
  • db: The list of strings to search.
  • options: The options for the search.
    • maxResults: The maximum number of results to return. Default is 5.
    • getPenalty: The function to calculate the penalty for the given characters.
    • getScore: The function to calculate the score for the given characters.
    • showScore: Whether to show the score in the result. Default is false.
    • caseSensitive: Whether to consider the case sensitivity. Default is false.
    • levelPenalty: The penalty for the level of the keyword in the object. Default is 1 (which is mean no penalty).
    • dropoutRate: The threshold for the dropout. Default is 0.8 (higher means less dropout).

Algorithms

I want to base on smith-waterman algorithm and modify some of the mark calculation to achieve some of the following goals:

  • Keyword appears earlier in the string, it should have a higher score. For example, if we search react in the list ['react hooks', 'common react mistakes'], 'react hooks' should and a higher order.

  • Case sensitivity should be considered. The weighting of case matching should be higher than the weighting of case mismatching.

Example

let fzearch: Fzearch;

const db = [
	'Algorithm of Searching Agentsz',
	'Debounce and Throttle',
	'React Hooks',
	'Persisting State in React',
	'Deep Copy and Shadow Copy in Javascript',
	'Common React Mistakes',
];

fzearch = new Fzearch(db);

console.log(fzearch.search('co', 5));
// [
//   'Common React Mistakes',
//   'Deep Copy and Shadow Copy in Javascript',
//   'Persisting State in React',
//   'React Hooks',
//   'Algorithm of Searching Agentsz'
// ]

Reference

fzearch's People

Contributors

momingse avatar

Stargazers

Sam Bulatov avatar

Watchers

 avatar

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.