aboutsummaryrefslogtreecommitdiff
path: root/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'base/src')
-rw-r--r--base/src/database.rs45
1 files changed, 42 insertions, 3 deletions
diff --git a/base/src/database.rs b/base/src/database.rs
index ca9360f..f1ae595 100644
--- a/base/src/database.rs
+++ b/base/src/database.rs
@@ -10,7 +10,11 @@ use jellycommon::{
};
use log::info;
use serde::{Deserialize, Serialize};
-use std::{borrow::Borrow, ops::Deref, path::Path};
+use std::{borrow::Borrow, fs::create_dir_all, ops::Deref, path::Path};
+use tantivy::{
+ schema::{Field, Schema, FAST, STORED, TEXT},
+ Index, IndexReader, ReloadPolicy,
+};
pub use redb::*;
@@ -26,13 +30,16 @@ pub const T_NODE_IMPORT: TableDefinition<&str, Ser<Vec<(Vec<usize>, Node)>>> =
pub struct DataAcid {
pub inner: redb::Database,
+ pub ft_node: NodeFulltextIndex,
}
impl DataAcid {
pub fn open(path: &Path) -> Result<Self, anyhow::Error> {
info!("database");
- let db = redb::Database::create(path)?;
- let r = Self { inner: db };
+ let db = redb::Database::create(path.join("data"))?;
+
+ let ft_node = NodeFulltextIndex::new(path)?;
+ let r = Self { inner: db, ft_node };
{
// this creates all tables such that read operations on them do not fail.
@@ -58,6 +65,38 @@ impl Deref for DataAcid {
}
}
+pub struct NodeFulltextIndex {
+ pub schema: Schema,
+ pub reader: IndexReader,
+ pub id: Field,
+ pub title: Field,
+ pub description: Field,
+ pub index: Index,
+}
+impl NodeFulltextIndex {
+ fn new(path: &Path) -> anyhow::Result<Self> {
+ let mut schema = Schema::builder();
+ let id = schema.add_text_field("id", TEXT | STORED | FAST);
+ let title = schema.add_text_field("title", TEXT);
+ let description = schema.add_text_field("description", TEXT);
+ let schema = schema.build();
+ create_dir_all(path.join("node_fts_index"))?;
+ let index = Index::create_in_dir(path.join("node_fts_index"), schema.clone())?;
+ let reader = index
+ .reader_builder()
+ .reload_policy(ReloadPolicy::OnCommitWithDelay)
+ .try_into()?;
+ Ok(Self {
+ index,
+ reader,
+ schema,
+ id,
+ description,
+ title,
+ })
+ }
+}
+
pub trait TableExt<Key, KeyRef, Value> {
fn get(self, db: &DataAcid, key: KeyRef) -> anyhow::Result<Option<Value>>;
fn insert(self, db: &DataAcid, key: KeyRef, value: Value) -> anyhow::Result<()>;