diff --git a/CHANGELOG.md b/CHANGELOG.md index 955540b55..c51f14b50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ See [STATUS.md](server/STATUS.md) to learn more about which features will remain - Switch to monorepo. Include `atomic-data-browser` in this repo #216 - Add Tables (edit, keyboard support, sorting, more) #638 +- The `parent` query param in `/search` has changed to `parents` and accepts an array of Subjects #677 ## [v0.34.3] - 2023-06-27 diff --git a/Cargo.lock b/Cargo.lock index 4d195a1f9..c99c8e95a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -296,7 +296,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -319,7 +319,7 @@ checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -433,7 +433,7 @@ checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -510,6 +510,7 @@ dependencies = [ "sanitize-filename", "serde", "serde_json", + "serde_with 3.3.0", "simple-server-timing-header", "static-files", "sysinfo", @@ -834,6 +835,7 @@ dependencies = [ "js-sys", "num-integer", "num-traits", + "serde", "time 0.1.44", "wasm-bindgen", "winapi", @@ -880,7 +882,7 @@ checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" dependencies = [ "bitflags", "clap_lex 0.2.4", - "indexmap", + "indexmap 1.9.1", "textwrap", ] @@ -909,7 +911,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1224,7 +1226,7 @@ dependencies = [ "proc-macro2", "quote", "smallvec", - "syn", + "syn 1.0.109", ] [[package]] @@ -1234,7 +1236,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfae75de57f2b2e85e8768c3ea840fd159c8f33e2b6522c7835b7abac81be16e" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1244,7 +1246,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1259,8 +1261,18 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core 0.20.3", + "darling_macro 0.20.3", ] [[package]] @@ -1274,7 +1286,21 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 1.0.109", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.38", ] [[package]] @@ -1283,9 +1309,20 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ - "darling_core", + "darling_core 0.13.4", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core 0.20.3", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -1295,7 +1332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" dependencies = [ "cfg-if", - "hashbrown", + "hashbrown 0.12.3", "lock_api", "once_cell", "parking_lot_core 0.9.3", @@ -1332,7 +1369,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn", + "syn 1.0.109", ] [[package]] @@ -1507,6 +1544,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.2.8" @@ -1748,7 +1791,7 @@ checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1969,7 +2012,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2064,7 +2107,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2079,7 +2122,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.1", "slab", "tokio", "tokio-util", @@ -2101,6 +2144,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" + [[package]] name = "heck" version = "0.3.3" @@ -2125,6 +2174,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "html2md" version = "0.2.14" @@ -2150,7 +2205,7 @@ dependencies = [ "markup5ever 0.10.1", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2164,7 +2219,7 @@ dependencies = [ "markup5ever 0.11.0", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2335,7 +2390,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown 0.14.1", + "serde", ] [[package]] @@ -2655,7 +2722,7 @@ dependencies = [ "cfg-if", "cssparser", "encoding_rs", - "hashbrown", + "hashbrown 0.12.3", "lazy_static", "lazycell", "memchr", @@ -2686,7 +2753,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" dependencies = [ - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -2982,7 +3049,7 @@ checksum = "be7d33be719c6f4d09e64e27c1ef4e73485dc4cc1f4d22201f89860a7fe22e22" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2994,7 +3061,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3066,7 +3133,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3171,7 +3238,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3237,7 +3304,7 @@ dependencies = [ "fnv", "futures-channel", "futures-util", - "indexmap", + "indexmap 1.9.1", "js-sys", "once_cell", "pin-project-lite", @@ -3525,7 +3592,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3539,7 +3606,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3577,7 +3644,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3605,7 +3672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd39bc6cdc9355ad1dc5eeedefee696bb35c34caf21768741e81826c0bbd7225" dependencies = [ "base64 0.13.0", - "indexmap", + "indexmap 1.9.1", "line-wrap", "serde", "time 0.3.14", @@ -3723,7 +3790,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -3746,9 +3813,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -3764,9 +3831,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -4282,22 +4349,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.152" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -4319,7 +4386,7 @@ checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4350,7 +4417,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" dependencies = [ "serde", - "serde_with_macros", + "serde_with_macros 1.5.2", +] + +[[package]] +name = "serde_with" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca3b16a3d82c4088f343b7480a93550b3eabe1a358569c2dfe38bbcead07237" +dependencies = [ + "base64 0.21.0", + "chrono", + "hex", + "indexmap 1.9.1", + "indexmap 2.0.2", + "serde", + "serde_json", + "serde_with_macros 3.3.0", + "time 0.3.14", ] [[package]] @@ -4359,10 +4443,22 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" dependencies = [ - "darling", + "darling 0.13.4", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_with_macros" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e6be15c453eb305019bfa438b1593c731f36a289a7853f7707ee29e870b3b3c" +dependencies = [ + "darling 0.20.3", "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -4384,7 +4480,7 @@ checksum = "74064874e9f6a15f04c1f3cb627902d0e6b410abbf36668afa873c61889f1763" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4616,7 +4712,7 @@ dependencies = [ "heck 0.3.3", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4630,6 +4726,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sysinfo" version = "0.26.2" @@ -4928,7 +5035,7 @@ dependencies = [ "heck 0.4.0", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "tauri-codegen", "tauri-utils", ] @@ -4993,7 +5100,7 @@ dependencies = [ "semver 1.0.13", "serde", "serde_json", - "serde_with", + "serde_with 1.14.0", "thiserror", "url", "walkdir", @@ -5079,7 +5186,7 @@ checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -5248,7 +5355,7 @@ version = "0.19.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825" dependencies = [ - "indexmap", + "indexmap 1.9.1", "serde", "serde_spanned", "toml_datetime", @@ -5295,7 +5402,7 @@ checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -5658,7 +5765,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -5692,7 +5799,7 @@ checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5799,7 +5906,7 @@ checksum = "eaebe196c01691db62e9e4ca52c5ef1e4fd837dcae27dae3ada599b5a8fd05ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -5919,7 +6026,7 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67a1062e555f7d9d66fd1130ed4f7c6ec41a47529ee0850cd0e926d95b26bb14" dependencies = [ - "syn", + "syn 1.0.109", "windows-tokens", ] diff --git a/Cargo.toml b/Cargo.toml index 278d69296..68787a223 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +workspace.resolver = "2" members = [ "server", "cli", diff --git a/browser/CHANGELOG.md b/browser/CHANGELOG.md index 3cec8f71c..1cf48a665 100644 --- a/browser/CHANGELOG.md +++ b/browser/CHANGELOG.md @@ -4,6 +4,8 @@ This changelog covers all three packages, as they are (for now) updated as a who ## UNRELEASED +- The `scope` option in `SearchOpts` has changed to `parents` and now accepts an array of subjects instead of a single subject. + ### Atomic Browser - Show resource usage in data view. diff --git a/browser/data-browser/src/routes/SearchRoute.tsx b/browser/data-browser/src/routes/SearchRoute.tsx index 52e802104..087d44ba8 100644 --- a/browser/data-browser/src/routes/SearchRoute.tsx +++ b/browser/data-browser/src/routes/SearchRoute.tsx @@ -37,7 +37,7 @@ export function Search(): JSX.Element { const [selectedIndex, setSelected] = useState(0); const { results, loading, error } = useServerSearch(query, { debounce: 0, - scope: scope || drive, + parents: scope || drive, filters, }); const navigate = useNavigate(); diff --git a/browser/data-browser/src/views/TablePage/EditorCells/useResourceSearch.ts b/browser/data-browser/src/views/TablePage/EditorCells/useResourceSearch.ts index b0b7271e0..90ebe736c 100644 --- a/browser/data-browser/src/views/TablePage/EditorCells/useResourceSearch.ts +++ b/browser/data-browser/src/views/TablePage/EditorCells/useResourceSearch.ts @@ -12,7 +12,7 @@ export function useResourceSearch( const searchOpts = useMemo( (): SearchOpts => ({ - scope: drive, + parents: drive, filters: classType ? { [urls.properties.isA]: classType } : undefined, }), [drive, classType], diff --git a/browser/lib/src/search.ts b/browser/lib/src/search.ts index a5342e245..aecf5444f 100644 --- a/browser/lib/src/search.ts +++ b/browser/lib/src/search.ts @@ -3,8 +3,8 @@ export interface SearchOpts { include?: boolean; /** Max of how many results to return */ limit?: number; - /** Subject of resource to scope the search to. This should be a parent of the resources you're looking for. */ - scope?: string; + /** Subjects of resource to scope the search to. This should be a list of parents of the resources you're looking for. */ + parents?: string[] | string; /** Property-Value pair of set filters. */ filters?: { [subject: string]: string; @@ -55,7 +55,7 @@ export function buildSearchSubject( query: string, opts: SearchOpts = {}, ) { - const { include = false, limit = 30, scope, filters } = opts; + const { include = false, limit = 30, parents, filters } = opts; const url = new URL(serverURL); url.pathname = 'search'; @@ -69,7 +69,15 @@ export function buildSearchSubject( include && url.searchParams.set('include', include.toString()); limit && url.searchParams.set('limit', limit.toString()); hasFilters && url.searchParams.set('filters', buildFilterString(filters)); - scope && url.searchParams.set('parent', scope); + + if (parents) { + if (Array.isArray(parents)) { + url.searchParams.append('parents', parents.join(',')); + } else { + url.searchParams.append('parents', parents); + } + } + // parents && url.searchParams.set('parents', JSON.stringify(parents)); return url.toString(); } diff --git a/server/Cargo.toml b/server/Cargo.toml index 052098bb9..d2748ddd9 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -38,6 +38,7 @@ rio_turtle = "0.7" rustls-pemfile = "1" sanitize-filename = "0.4" serde_json = "1" +serde_with = "3.3.0" simple-server-timing-header = "0.1.0" static-files = "0.2" tantivy = "0.19" diff --git a/server/src/handlers/search.rs b/server/src/handlers/search.rs index f975747f3..7013f4fbe 100644 --- a/server/src/handlers/search.rs +++ b/server/src/handlers/search.rs @@ -10,6 +10,7 @@ use crate::{ use actix_web::{web, HttpResponse}; use atomic_lib::{errors::AtomicResult, urls, Db, Resource, Storelike}; use serde::Deserialize; +use serde_with::{formats::CommaSeparator, StringWithSeparator}; use simple_server_timing_header::Timer; use tantivy::{ collector::TopDocs, @@ -22,6 +23,9 @@ use tracing::instrument; type Queries = Vec<(Occur, Box)>; +// All this serde stuff is to allow comma separated lists in the query params. +#[serde_with::serde_as] +#[serde_with::skip_serializing_none] #[derive(Deserialize, Debug)] pub struct SearchQuery { /// The text search query entered by the user in the search box @@ -30,8 +34,9 @@ pub struct SearchQuery { pub include: Option, /// Maximum amount of results pub limit: Option, - /// Only include resources that have this resource as its ancestor - pub parent: Option, + /// Only include resources that have one of these resources as its ancestor + #[serde_as(as = "Option>")] + pub parents: Option>, /// Filter based on props, using tantivy QueryParser syntax. /// e.g. `prop:val` or `prop:val~1` or `prop:val~1 AND prop2:val2` /// See https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html @@ -147,9 +152,14 @@ fn query_from_params( ) -> AtomicServerResult { let mut query_list: Queries = Vec::new(); - if let Some(parent) = ¶ms.parent { - let query = build_parent_query(parent, fields, &appstate.store)?; + if let Some(parents) = ¶ms.parents { + let mut queries: Vec> = Vec::new(); + for parent in parents { + let boxed_q = build_parent_query(parent, fields, &appstate.store)?; + queries.push(Box::new(boxed_q)); + } + let query = BooleanQuery::union(queries); query_list.push((Occur::Must, Box::new(query))); }