From c988e7db759966d9586471e8cfcfd0d91e855dc0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 15 Apr 2024 15:19:29 +0200 Subject: fulltext search pt.2 --- import/src/db.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'import/src') diff --git a/import/src/db.rs b/import/src/db.rs index 88c5601..4c62681 100644 --- a/import/src/db.rs +++ b/import/src/db.rs @@ -1,7 +1,9 @@ use std::collections::HashMap; use anyhow::anyhow; -use jellybase::database::{DataAcid, ReadableTable, Ser, T_NODE, T_NODE_EXTENDED, T_NODE_IMPORT}; +use jellybase::database::{ + doc, DataAcid, ReadableTable, Ser, T_NODE, T_NODE_EXTENDED, T_NODE_IMPORT, +}; use jellycommon::{ExtendedNode, Node}; use log::info; use std::sync::RwLock; @@ -114,6 +116,13 @@ impl ImportStorage for MemoryStorage<'_> { table.drain::<&str>(..)?; drop(table); txn.commit()?; + self.db + .node_index + .writer + .read() + .unwrap() + .delete_all_documents()?; + self.db.node_index.writer.write().unwrap().commit()?; Ok(()) } fn get_partial_parts(&self, id: &str) -> anyhow::Result, Node)>> { @@ -128,9 +137,22 @@ impl ImportStorage for MemoryStorage<'_> { fn insert_complete_node(&self, id: &str, node: Node) -> anyhow::Result<()> { let txn_write = self.db.inner.begin_write()?; let mut t_node = txn_write.open_table(T_NODE)?; - t_node.insert(id, Ser(node))?; + t_node.insert(id, Ser(node.clone()))?; drop(t_node); txn_write.commit()?; + + self.db + .node_index + .writer + .read() + .unwrap() + .add_document(doc!( + self.db.node_index.id => node.public.id.unwrap_or_default(), + self.db.node_index.title => node.public.title.unwrap_or_default(), + self.db.node_index.description => node.public.description.unwrap_or_default(), + self.db.node_index.releasedate => node.public.release_date.unwrap_or_default(), + self.db.node_index.f_index => node.public.index.unwrap_or_default() as u64, + ))?; Ok(()) } @@ -160,6 +182,7 @@ impl ImportStorage for MemoryStorage<'_> { } fn finish(&self) -> anyhow::Result<()> { + self.db.node_index.reader.reload()?; Ok(()) } } -- cgit v1.2.3-70-g09d2