diff options
-rw-r--r-- | import/src/db.rs | 56 | ||||
-rw-r--r-- | server/src/routes/ui/search.rs | 3 |
2 files changed, 30 insertions, 29 deletions
diff --git a/import/src/db.rs b/import/src/db.rs index 49c2f0e..c667cf5 100644 --- a/import/src/db.rs +++ b/import/src/db.rs @@ -49,12 +49,7 @@ impl ImportStorage for DatabaseStorage<'_> { Ok(value.value().0) } 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))?; - drop(t_node); - txn_write.commit()?; - Ok(()) + insert_complete_node(&self.db, id, node) } fn add_partial_node(&self, id: &str, index_path: &[usize], node: Node) -> anyhow::Result<()> { @@ -92,6 +87,8 @@ impl ImportStorage for DatabaseStorage<'_> { table.drain::<&str>(..)?; drop(table); txn.commit()?; + + self.db.node_index.writer.write().unwrap().commit()?; Ok(()) } } @@ -135,27 +132,7 @@ impl ImportStorage for MemoryStorage<'_> { .to_owned()) } 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.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 => DateTime::from_timestamp_millis(node.public.release_date.unwrap_or_default()), - self.db.node_index.f_index => node.public.index.unwrap_or_default() as u64, - )) - .context("inserting document")?; - - Ok(()) + insert_complete_node(&self.db, id, node) } fn add_partial_node(&self, id: &str, index_path: &[usize], node: Node) -> anyhow::Result<()> { @@ -184,7 +161,30 @@ impl ImportStorage for MemoryStorage<'_> { } fn finish(&self) -> anyhow::Result<()> { - self.db.node_index.reader.reload()?; + self.db.node_index.writer.write().unwrap().commit()?; Ok(()) } } + +fn insert_complete_node(db: &DataAcid, id: &str, node: Node) -> anyhow::Result<()> { + let txn_write = db.inner.begin_write()?; + let mut t_node = txn_write.open_table(T_NODE)?; + t_node.insert(id, Ser(node.clone()))?; + drop(t_node); + txn_write.commit()?; + + db + .node_index + .writer + .read() + .unwrap() + .add_document(doc!( + db.node_index.id => node.public.id.unwrap_or_default(), + db.node_index.title => node.public.title.unwrap_or_default(), + db.node_index.description => node.public.description.unwrap_or_default(), + db.node_index.releasedate => DateTime::from_timestamp_millis(node.public.release_date.unwrap_or_default()), + db.node_index.f_index => node.public.index.unwrap_or_default() as u64, + )) + .context("inserting document")?; + Ok(()) +} diff --git a/server/src/routes/ui/search.rs b/server/src/routes/ui/search.rs index f87a13b..4ea5716 100644 --- a/server/src/routes/ui/search.rs +++ b/server/src/routes/ui/search.rs @@ -64,6 +64,7 @@ pub async fn r_search<'a>( None }; let search_dur = timing.elapsed(); + let query = query.unwrap_or_default().to_string(); Ok(LayoutPage { title: "Search".to_string(), @@ -71,7 +72,7 @@ pub async fn r_search<'a>( content: markup::new! { h1 { "Search" } form[action="", method="GET"] { - input[type="text", name="query", placeholder="Search Term"]; + input[type="text", name="query", placeholder="Search Term", value=&query]; input[type="submit", value="Search"]; } @if let Some((count, results)) = &results { |