aboutsummaryrefslogtreecommitdiff
path: root/import/src
diff options
context:
space:
mode:
Diffstat (limited to 'import/src')
-rw-r--r--import/src/db.rs27
1 files changed, 25 insertions, 2 deletions
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<Vec<(Vec<usize>, 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(())
}
}