2 Commits

Author SHA1 Message Date
d39e876885 Slower: 1000ms 2024-10-30 21:39:43 +00:00
1e8d5d6311 Experimental: Cosine-Distance Matcher 2024-10-30 21:10:41 +00:00
3 changed files with 13 additions and 19 deletions

2
schemsearch-cli/Cargo.toml Normal file → Executable file
View File

@@ -13,7 +13,7 @@ schemsearch-sql = { path = "../schemsearch-sql", optional = true }
clap = { version = "4.1.8", features = ["cargo"] }
futures = { version = "0.3", optional = true }
sqlx = { version = "0.8", features = [ "runtime-async-std-native-tls" , "mysql" ], optional = true }
sqlx = { version = "0.7", features = [ "runtime-async-std-native-tls" , "mysql" ], optional = true }
rayon = "1.7.0"
indicatif = { version = "0.17.3", features = ["rayon"] }
serde = "1.0.157"

View File

@@ -43,40 +43,34 @@ pub fn search(
let schem_height = schem.height as usize;
let schem_length = schem.length as usize;
let skip_amount = ceil((pattern_blocks * (1.0 - search_behavior.threshold)) as f64, 0) as i32;
let pattern_vec_length = pattern_schem.block_data.iter().map(|x| x * x).sum::<i32>();
for y in 0..=schem_height - pattern_height {
for z in 0..=schem_length - pattern_length {
for x in 0..=schem_width - pattern_width {
let mut not_matching = 0;
'outer:
let mut dot_p: i32 = 0;
let mut schem_vec_length = 0;
for j in 0..pattern_height {
for k in 0..pattern_length {
'inner:
for i in 0..pattern_width {
let index = (x + i) + schem_width * ((z + k) + (y + j) * schem_length);
let pattern_index = i + pattern_width * (k + j * pattern_length);
let data = unsafe { *schem_data.add(index) };
let pattern_data = unsafe { *pattern_data.add(pattern_index) };
if (search_behavior.ignore_air && data != *air_id) || (search_behavior.air_as_any && pattern_data != *air_id) {
continue 'inner;
}
if data != pattern_data {
not_matching += 1;
if not_matching >= skip_amount {
break 'outer;
}
}
dot_p += unsafe { *pattern_data.add(pattern_index) * *schem_data.add(index) };
schem_vec_length += unsafe { *schem_data.add(index) * *schem_data.add(index) };
}
}
}
if not_matching < skip_amount {
let sim = dot_p as f32 / ((pattern_vec_length as f32).sqrt() * (schem_vec_length as f32).sqrt());
if sim > search_behavior.threshold {
matches.push(Match {
x: x as u16,
y: y as u16,
z: z as u16,
percent: (i_pattern_blocks - not_matching) as f32 / pattern_blocks,
percent: sim,
});
}
}

View File

@@ -7,7 +7,7 @@ license = "AGPL-3.0-or-later"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sqlx = { version = "0.8", features = [ "runtime-async-std-native-tls" , "mysql" ] }
sqlx = { version = "0.7", features = [ "runtime-async-std-native-tls" , "mysql" ] }
schemsearch-lib = { path = "../schemsearch-lib" }
schemsearch-files = { path = "../schemsearch-files" }