• Stars
    star
    2,974
  • Rank 15,213 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌊 Blazing fast 1kb search library

Wade

Blazing fast 1kb search

Build Status

Installation

NPM

npm install wade

CDN

<script src="https://unpkg.com/wade"></script>

Usage

Initialize Wade with an array of data.

const search = Wade(["Apple", "Lemon", "Orange", "Tomato"]);

Now you can search for a query within the data, and Wade will return results. Each result will include the index of the item in the data it corresponds to along with a score depending on the relevance of the query to the result.

search("App");

/*
  [{
    index: 0,
    score: 1.25
  }]
*/

Combined with JavaScript libraries like Moon, you can create a real-time search.

Loading/Saving Index

To save an index as a String, use Wade.save on a search function.

For example:

// Create the search function
const search = Wade(["Apple", "Lemon", "Orange", "Tomato"]);
const index = Wade.save(search);

// Save `index`

Later, you can get the same search function without having Wade recreate an index every time by doing:

// Retrieve `index`, then
const search = Wade(index);

index is a String and can be saved to a file.

Processors

Wade uses a set of processors to preprocess data and search queries. By default, these will:

  • Make everything lowercase
  • Remove punctuation
  • Remove stop words

A process consists of different functions that process a string and modify it in some way, and return the transformed string.

You can easily modify the processors as they are available in Wade.config.processors, for example:

// Don't preprocess at all
Wade.config.processors = [];

// Add custom processor to remove periods
Wade.config.processors.push(function(str) {
  return str.replace(/\./g, "");
});

All functions will be executed in the order of the array (0-n) and they will be used on each document in the data.

The stop words can be configured to include any words you like, and you can access the array of stop words by using:

Wade.config.stopWords = [/* array of stop words */];

The punctuation regular expression used to remove punctuation can be configured with:

Wade.config.punctuationRE = /[.!]/g; // should contain punctuation to remove

Algorithm

First, an index is generated from the data. When performing a search, the following happens:

  • The search query is processed.
  • The search query is tokenized into terms.
  • Each term except the last is searched for exactly and scores for each item in the data are updated according to the relevance of the term to the data.
  • The last keyword is treated as a prefix, and Wade performs a depth-first search and updates the score for all data prefixed with this term using the relevance weight for the term. This allows for searching as a user types.

In-depth explanations of the algorithm are available on the blog post and pdf.

Support

Support Wade on Patreon to help sustain the development of the project. The maker of the project works on open source for free. If you or your company depend on this project, then it makes sense to donate to ensure that the project is maintained.

License

Licensed under the MIT License by Kabir Shah

More Repositories

1

moon

🌙 The minimal & fast library for functional user interfaces
JavaScript
5,993
star
2

wing

💎 A beautiful CSS framework designed for minimalists.
CSS
2,007
star
3

slash

🔑 Fast, efficient hash
C
102
star
4

colicious

😋 Delicious Color Generator
CSS
82
star
5

snip

✂️ dead-simple URL shortener
JavaScript
60
star
6

sold

✒️ minimal static site generator
JavaScript
52
star
7

moon-router

Router for Moon
JavaScript
51
star
8

ice

◽️ A bot that crafts words and images.
Python
46
star
9

monx

Clean State Management for Moon
JavaScript
46
star
10

arc

⚡ Minimal Hybrid Kernel
C
45
star
11

moon-cli

✨ Easily scaffold a Moon project
JavaScript
27
star
12

moon-ssr

Server Side Rendering for Moon
JavaScript
24
star
13

lock

💥 self destructing messages
HTML
24
star
14

alter

convert text to images
CSS
20
star
15

paint

🎨 Lightweight DOM/Events Library w/ JQuery Like API
JavaScript
19
star
16

spark

✨ Flexible Artificial Intelligence Library for Python
Python
19
star
17

coat

📦 Fast reverse proxy and cache
C
15
star
18

cheat

📝 cheatsheet for frontend, coding, and interview questions
JavaScript
11
star
19

bookmarklets

Fun Bookmarklets I made for fun
JavaScript
10
star
20

nox

⚫ Elegant color scheme and Vim configuration
Vim Script
10
star
21

parcel-plugin-moon

Parcel plugin for Moon.
JavaScript
10
star
22

Me

HTML
9
star
23

sly

😏 Making CSS Better
JavaScript
9
star
24

throw

✒️ throwaway notes stored in the URL
HTML
9
star
25

marka

minimal markdown parser
JavaScript
9
star
26

colex

change readability of text
JavaScript
9
star
27

slashjs

Slash Hash function in JavaScript
JavaScript
8
star
28

grain

Minimal structural styles
CSS
7
star
29

valon

📖 A constructed language based on functions.
JavaScript
7
star
30

moon-component-compiler

Compiler for Single File Moon Components
JavaScript
7
star
31

blog

HTML
7
star
32

sparkjs

✨ [DISCONTINUED] JS AI library
JavaScript
6
star
33

elto

minimal, ultralight, web framework for node
JavaScript
6
star
34

break-design

A collection of beautiful links.
HTML
5
star
35

apto

C
5
star
36

text-rnn

RNN to generate text
Python
5
star
37

breeze

Blazing fast web framework for Crystal
Crystal
5
star
38

moon-template

Moon CLI template
JavaScript
5
star
39

moon-bars

Sleek bar graph component for Moon
JavaScript
4
star
40

lamp

a lavalamp
HTML
4
star
41

moon-loader

Webpack loader for Moon
JavaScript
4
star
42

Main180

💻 Making 180 Websites in 180 Days
HTML
4
star
43

language-moon

Atom syntax highlighting for Moon components
MoonScript
4
star
44

assemble

an ebook explaining the process of making things
CSS
4
star
45

gradual

tasks with a beautiful UI
JavaScript
3
star
46

moonify

Browserify transform for Moon Components
JavaScript
3
star
47

voke

Event Emitter
JavaScript
3
star
48

kov

Markov chains made simple
JavaScript
3
star
49

rollup-plugin-moon

Rollup plugin for Moon.
JavaScript
3
star
50

lines

see how many lines of code a person has written on Github
JavaScript
3
star
51

ama

❓ Ask Me Anything
3
star
52

plate

🍽 A boilerplate for Node web apps
JavaScript
2
star
53

sled

JavaScript
1
star
54

twist

HTML
1
star
55

hexu

add color to your logs
JavaScript
1
star
56

code-highlighter

JavaScript
1
star