#pallet #document #sled #tantivy #built #store #search

pallet-macros

使用sled和tantivy构建的文档存储

3个不稳定版本

0.4.0 2020年2月28日
0.3.2 2020年2月21日
0.3.0 2020年2月20日

#tantivy 中排名46


pallet 使用

MIT 许可证

9KB
202

pallet

Docs Crates.io

一个基于sledtantivy 的可搜索文档数据存储。

sled数据库提供一个类型化树接口,具有标准数据存储操作(findcreateupdatedelete),同时也支持Lucene/Elasticsearch风格的搜索。

包含的pallet_macros包提供了一个简单的方式来为数据结构推导pallet::DocumentLike

用法

#[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

请参阅用法示例。以下属性可以用于自定义实现:

  • tree_name:一个容器级别属性,用于指定sled::Tree名称。
  • index_field_name:重命名搜索模式中的字段。
  • index_field_type:设置索引字段类型,必须实现Into<tantivy::schema::Value>
  • index_field_options:设置索引字段选项。默认情况下,String的选项为tantivy::schema::TEXT,而数字类型的选项为tantivy::schema::INDEXED
  • default_search_field:将此字段包含在默认搜索字段列表中。
  • skip_indexing:不要索引此字段。

更新日志

0.7.0

  • 更新sled/tantivy依赖项(感谢@lberezy)

0.6.0

  • 添加serde-cbor序列化支持(感谢@minioin)

0.5.0

  • Document 内部类型上添加 Deref
  • 使索引写入器持久化

0.4.0

  • 添加各种构建器。
  • indextree 功能拆分出来。
  • 设置 search::Searcher 特性和其他搜索辅助器。

0.3.2

  • 添加一些文档

0.3.0

  • pallet_macros 添加到 derive pallet::DocumentLike

当前版本:0.7.0

许可:MIT

依赖项

约 1.5MB
约 34K SLoC