3个不稳定版本
0.4.0 | 2020年2月28日 |
---|---|
0.3.2 | 2020年2月21日 |
0.3.0 | 2020年2月20日 |
在#tantivy 中排名46
被pallet 使用
9KB
202 行
pallet
一个基于sled
和 tantivy
的可搜索文档数据存储。
为sled
数据库提供一个类型化树接口,具有标准数据存储操作(find
、create
、update
、delete
),同时也支持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
- 添加各种构建器。
- 将
index
和tree
功能拆分出来。 - 设置
search::Searcher
特性和其他搜索辅助器。
0.3.2
- 添加一些文档
0.3.0
- 将
pallet_macros
添加到 derivepallet::DocumentLike
当前版本:0.7.0
许可:MIT
依赖项
约 1.5MB
约 34K SLoC