Coder Social home page Coder Social logo

katu37-cyber / porigon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcuelenaere/porigon

0.0 0.0 0.0 89 KB

Lightweight FST-based autocompleter library written in Rust, targeting WebAssembly and data stored in-memory

License: MIT License

Shell 0.67% JavaScript 13.04% Rust 86.29%

porigon's Introduction

porigon

Lightweight FST-based autocompleter library written in Rust, targeting WebAssembly and data stored in-memory

Build status

Licensed under MIT.

Intended usecase

The idea of this library is to have a lightweight, yet idiomatic API around the fst crate that allows you to construct, serialize/deserialize and query FSTs in an WebAssembly environment. It's an ideal starting point for building an autocompleter service that can be used on the web, the edge (eg Cloudflare Worker) or the backend-side (node.js).

Existing solutions like eg tantivy are not fitting as they're too heavyweight (wasm binary size is over 1MB) or not compilable to WebAssembly. If you're looking for a more full fledged full-text search engine, take a look at the list of alternatives at the bottom.

Documentation

https://docs.rs/porigon

Installation

Simply add a corresponding entry to your Cargo.toml dependency list:

[dependencies]
porigon = "0.1.0"

Example

This example demonstrates building a Searchable in memory, executing a StartsWith query against it and collecting the top 3 documents with TopScoreCollector.

use porigon::{Searchable, TopScoreCollector};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let items = vec!(
    ("bar".as_bytes(), 1),
    ("foo".as_bytes(), 2),
    ("foobar".as_bytes(), 3)
  );
  let searchable = Searchable::build_from_iter(items)?;

  let mut collector = TopScoreCollector::new(3);
  collector.consume_stream(
    searchable
      .starts_with("foo")
      .rescore(|_, index, _| index * 2)
  );

  let docs = collector.top_documents();
  assert_eq!(docs[0].index, 3);
  
  Ok(())
}

Check out the documentation or wasm-example for a more examples.

Alternatives

If you're looking for a more general-purpose full-text search engine, take a look at these alternatives:

porigon's People

Contributors

dependabot[bot] avatar mcuelenaere 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.