Giter VIP home page Giter VIP logo

pallet's Introduction

pallet

Docs Crates.io

A searchable document datastore built on sled and tantivy.

Provides a typed-tree interface to a sled database, with standard datastore ops (find, create, update, delete), but also Lucene/Elasticsearch style searching.

The included pallet_macros crate provides an easy way to derive pallet::DocumentLike for data structs.

Usage

#[macro_use]
extern crate serde;

#[derive(Serialize, Deserialize, Debug, pallet::DocumentLike)]
#[pallet(tree_name = "books")]
pub struct Book {
    #[pallet(default_search_field)]
    title: String,
    #[pallet(default_search_field)]
    description: Option<String>,
    #[pallet(index_field_type = "u64")]
    rating: u8,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let temp_dir = tempfile::TempDir::new_in(".")?;

    let db = sled::open(temp_dir.path().join("db"))?;

    let store = pallet::Store::builder().with_db(db).with_index_dir(temp_dir.path()).finish()?;

    let books = vec![
        Book {
            title: "The Old Man and the Sea".into(),
            description: Some(
                "He was an old man who fished alone in a skiff in \
            the Gulf Stream and he had gone eighty-four days \
            now without taking a fish."
                    .into(),
            ),
            rating: 10,
        },
        Book {
            title: "The Great Gatsby".into(),
            description: Some("About a man and some other stuff".into()),
            rating: 8,
        },
    ];

    let _ = store.create_multi(&books)?;

    let books = store.search("man AND rating:>8")?;

    println!("{:?}", books);

    Ok(())
}

pallet_macros

See the example for usage. The following attributes can be used to customize the implementation:

  • tree_name: A container level attribute to specify the sled::Tree name.
  • index_field_name: Rename the field in the search schema.
  • index_field_type: Set the index field type, must implement Into<tantivy::schema::Value>.
  • index_field_options: Set the index field options. By default, the options for String is tantivy::schema::TEXT, and the options for numeric types is tantivy::schema::INDEXED.
  • default_search_field: Include this field in the list of default search fields.
  • skip_indexing: Do not index this field.

Changelog

0.7.0

  • Update sled/tantivy deps (thanks @lberezy)

0.6.0

  • Add serde-cbor serialization support (thanks @minioin)

0.5.0

  • Add Deref to inner type on Document
  • Make index writer persistent

0.4.0

  • Add various builders.
  • Split out index and tree functionality.
  • Set up search::Searcher trait and other search helpers.

0.3.2

  • Add some docs

0.3.0

  • Add pallet_macros to derive pallet::DocumentLike

Current version: 0.7.0

License: MIT

pallet's People

Contributors

kardeiz avatar minioin avatar lberezy avatar nicohman avatar

Watchers

James Cloos avatar  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.