LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Show an empty view when Find Similar has no matches
NetterSilver1c815fb3f823
diff --git a/crates/engine/src/cmd/cull.rs b/crates/engine/src/cmd/cull.rsindex 676519d29..c5d9a1854 100644--- a/crates/engine/src/cmd/cull.rs+++ b/crates/engine/src/cmd/cull.rs@@ -113,6 +113,10 @@ fn find_similar(s: &mut Session, p: &Value) -> Result<Value> {hits.sort_by(|a, b| b.1.total_cmp(&a.1));if p.get("filter").and_then(Value::as_bool).unwrap_or(true) {s.filter.only = hits.iter().map(|h| h.0).collect();+ if s.filter.only.is_empty() {+ // an empty `only` means "no constraint": use an id no photo has so no hits show no photos+ s.filter.only = vec![PhotoId(u64::MAX)];+ }}Ok(json!({"photos": hits.iter().map(|(i, v)| json!({"id": i.0, "similarity": (v * 1000.0).round() / 1000.0})).collect::<Vec<_>>()}))}diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 400135ce0..f4ac5ae5f 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -1102,6 +1102,16 @@ fn find_similar_filters_to_look_alikes() {assert!(s.visible_cloned().len() > vis.len());}+#[test]+fn find_similar_with_no_hits_shows_no_photos() {+ let mut s = demo();+ let r = s.execute("library.findSimilar", &json!({"similarity": 1.5})).unwrap();+ assert_eq!(r["photos"].as_array().map(Vec::len), Some(0));+ assert_eq!(s.visible_cloned().len(), 0, "an empty Find Similar result must show no photos, not the whole library");+ s.execute("library.clearFilter", &json!({})).unwrap();+ assert_eq!(s.visible_cloned().len(), s.catalog.len(), "Clear Filters brings everything back");+}+#[test]fn quick_develop_adds_to_each_photo() {use lightcraft_catalog::PhotoId;