Giter Club home page Giter Club logo

tinysearch's Introduction

tinysearch

CI

TinySearch is a lightweight, fast, full-text search engine. It is designed for static websites.

TinySearch is written in Rust, and then compiled to WebAssembly to run in the browser.
It can be used together with static site generators such as Jekyll, Hugo, zola, Cobalt, or Pelican.

Demo

How it works

tinysearch is a Rust/WASM port of the Python code from the article "Writing a full-text search engine using Bloom filters". It can be seen as an alternative to lunr.js and elasticlunr, which are quite heavy for smaller websites and require a lot of JavaScript.

The idea of tinysearch is to generate a small, self-contained WASM module from a list of articles on your website and run it directly on the frontend inside browsers.

Users

Limitations

  • Only searches for entire words. There are no search suggestions (yet).
  • Since we bundle all search indices for all articles into one static binary, we recommend to only use it for small- to medium-size websites. Expect around 4kB (non-compressed) per article.

Installation

wasm-pack is required to build the WASM module. Install it with

cargo install wasm-pack

To optimize the JavaScript output, you'll also need terser:

npm install terser -g

If you want to make the WebAssembly as small as possible, we recommend to install binaryen as well. On macOS you can install it with homebrew:

brew install binaryen

Alternatively, you can download the binary from the release page or use your OS package manager.

After that, you can install tinysearch itself:

cargo install tinysearch

Usage

As an input, we require a JSON file, which contains the content to index. Check out this example file.

tinysearch fixtures/index.json

โ„น๏ธ You can take a look at the code examples for different static site generators here.
โ„น๏ธ The body field in the JSON document is optional and can be skipped to just index post titles.

This will create a WASM module and the JavaScript glue code to integrate it into your homepage. You can open the demo.html from any webserver to see the result.

For example, Python has a built-in webserver for testing:

python3 -m http.server 

then browse to http://0.0.0.0:8000/demo.html to see the result.

For advanced usage options, try

tinysearch --help

Please check what's required to host WebAssembly in production -- you will need to explicitly set mime gzip types.

Docker

If a full Rust setup, you can also use our nightly-built Docker images.

Build

Available buid args:

  • WASM_REPO
  • WASM_BRANCH
  • TINY_REPO
  • TINY_BRANCH
  • TINY_MAGIC (for a magic number see tinysearch#111)

Demo

wget https://raw.githubusercontent.com/tinysearch/tinysearch/master/fixtures/index.json
docker run $PWD:/tmp tinysearch/cli index.json

Custom repo/branch build

docker build --build-arg WASM_BRANCH=master --build-arg TINY_MAGIC=64 -t tinysearch/cli .

By default most recent stable alpine rust image is used. To get nightly just run

docker build --build-arg RUST_IMAGE=rustlang/rust:nightly-alpine -t tinysearch/cli:nightly .

Maintainers

  • Matthias Endler (@mre)
  • Jorge-Luis Betancourt (@jorgelbg)
  • Mad Mike (@fluential)

License

tinysearch is licensed under either of

at your option.

tinysearch's People

Contributors

mre avatar dependabot-preview[bot] avatar fluential avatar vishalsodani avatar okrplay avatar jorgelbg avatar ninjani avatar lapoigne avatar djugei avatar shuni64 avatar felipe-fg avatar lord-re avatar mh84 avatar petertrotman avatar tshepang 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.