1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Nostr event database

mod db;
mod error;
mod event;
mod filter;
mod key;
pub use secp256k1;

pub use {
    db::CheckEventResult, db::Db, db::Iter, error::Error, event::now, event::ArchivedEventIndex,
    event::Event, event::EventIndex, event::FromEventData, filter::Filter, filter::TagList,
};

pub use nostr_kv as kv;

/// Stats of query
#[derive(Debug, Clone)]
pub struct Stats {
    pub scan_index: u64,
    pub get_data: u64,
    pub get_index: u64,
}

#[cfg(feature = "search")]
use charabia::Segment;

#[cfg(feature = "search")]
/// segment keywords by charabia
pub fn segment(content: &str) -> Vec<Vec<u8>> {
    let iter = content.segment_str();
    let mut words = iter
        .filter_map(|s| {
            let s = s.to_lowercase();
            let bytes = s.as_bytes();
            // limit size
            if bytes.len() < 255 {
                Some(bytes.to_vec())
            } else {
                None
            }
        })
        .collect::<Vec<_>>();
    words.sort();
    words.dedup();
    words
}