mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-27 07:46:25 +00:00
feat(core): hubs, tag pages and types, with ffi, history and import support
Hubs and templates are page kinds; tags are pages of kind tag linked by a TAGGED edge; types are plain names on the page. Schema v5. Snapshots carry synapse-kind/tags/types. Also adapts search, import and server tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
91a8276966
commit
b800248d67
35 files changed
+7983
-141
No files matched your search
@@ -1,4 +1,5 @@
|
||||
//! tantivy-backed full-text index: one document per block and one per page (title + aliases).
|
||||
//! tantivy-backed full-text index: one document per block and one per page (title + aliases,
|
||||
//! plus the description of hubs as content).
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::{Filter, JournalFilter, Scope};
|
||||
@@ -184,6 +185,7 @@ impl FullText {
|
||||
id: Uuid,
|
||||
title: &str,
|
||||
aliases: &[String],
|
||||
description: &str,
|
||||
day: i64,
|
||||
journal: bool,
|
||||
) -> Result<()> {
|
||||
@@ -196,6 +198,9 @@ impl FullText {
|
||||
for a in aliases {
|
||||
d.add_text(self.f.title, a);
|
||||
}
|
||||
if !description.is_empty() {
|
||||
d.add_text(self.f.content, description);
|
||||
}
|
||||
d.add_i64(self.f.day, day);
|
||||
d.add_u64(self.f.journal, journal as u64);
|
||||
self.writer.add_document(d)?;
|
||||
|
||||
@@ -318,7 +318,8 @@ impl Search {
|
||||
Some(d) => (day_of_date(d), true),
|
||||
None => (day_of_ms(p.updated_at), false),
|
||||
};
|
||||
self.ft.upsert_page(id, &p.title, &aliases, day, journal)?;
|
||||
self.ft
|
||||
.upsert_page(id, &p.title, &aliases, &p.description, day, journal)?;
|
||||
}
|
||||
None => {
|
||||
self.ft.delete(id);
|
||||
@@ -350,7 +351,8 @@ impl Search {
|
||||
Some(d) => (day_of_date(d), true),
|
||||
None => (day_of_ms(p.updated_at), false),
|
||||
};
|
||||
self.ft.upsert_page(p.id, &p.title, &al, day, journal)?;
|
||||
self.ft
|
||||
.upsert_page(p.id, &p.title, &al, &p.description, day, journal)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -40,15 +40,15 @@ pub(crate) fn quantize(v: &[f32]) -> (Vec<i8>, f32) {
|
||||
|
||||
fn dot(row: &[i8], q: &[f32]) -> f32 {
|
||||
let mut acc = [0f32; 8];
|
||||
let mut rc = row.chunks_exact(8);
|
||||
let mut qc = q.chunks_exact(8);
|
||||
for (r, c) in (&mut rc).zip(&mut qc) {
|
||||
let (rc, r_rem) = row.as_chunks::<8>();
|
||||
let (qc, q_rem) = q.as_chunks::<8>();
|
||||
for (r, c) in rc.iter().zip(qc) {
|
||||
for i in 0..8 {
|
||||
acc[i] += r[i] as f32 * c[i];
|
||||
}
|
||||
}
|
||||
let mut s: f32 = acc.iter().sum();
|
||||
for (r, c) in rc.remainder().iter().zip(qc.remainder()) {
|
||||
for (r, c) in r_rem.iter().zip(q_rem) {
|
||||
s += *r as f32 * c;
|
||||
}
|
||||
s
|
||||
|
||||
@@ -331,3 +331,21 @@ fn store_inside_graph_transaction_and_rename_delete() {
|
||||
assert!(s.search(&g, "ferris", &f, 10).unwrap().is_empty());
|
||||
assert_eq!(s.vector_counts(&g, "test/hash").unwrap(), (1, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hub_titles_and_descriptions_are_indexed() {
|
||||
let (_d, g) = setup();
|
||||
let h = g.create_hub("Anime", "Japanese animation series").unwrap();
|
||||
add(&g, "Other", "nothing related");
|
||||
let mut s = Search::open(&g).unwrap();
|
||||
s.sync(&g).unwrap();
|
||||
let f = Filter::default();
|
||||
let hits = s.search(&g, "animation", &f, 5).unwrap();
|
||||
assert_eq!(hits[0].kind, HitKind::Page);
|
||||
assert_eq!(hits[0].page_id, h.id);
|
||||
assert_eq!(s.search(&g, "anime", &f, 5).unwrap()[0].page_id, h.id);
|
||||
g.set_hub_description(h.id, "Cartoons from Japan").unwrap();
|
||||
s.sync(&g).unwrap();
|
||||
assert!(s.search(&g, "animation", &f, 5).unwrap().is_empty());
|
||||
assert_eq!(s.search(&g, "cartoons", &f, 5).unwrap()[0].page_id, h.id);
|
||||
}
|
||||
Reference in new issue
Block a user