diff --git a/src/db.rs b/src/db.rs index b645fdc..bed22b1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -529,22 +529,42 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec>) { for auth in authvec { match hex_range(auth) { Some(HexSearch::Exact(ex)) => { - auth_searches.push("author=? OR delegated_by=?".to_owned()); - params.push(Box::new(ex.clone())); + auth_searches.push("author=?".to_owned()); params.push(Box::new(ex)); } Some(HexSearch::Range(lower, upper)) => { auth_searches.push( - "(author>? AND author? AND delegated_by? AND author { - auth_searches.push("author>? OR delegated_by>?".to_owned()); - params.push(Box::new(lower.clone())); + auth_searches.push("author>?".to_owned()); + params.push(Box::new(lower)); + } + None => { + info!("Could not parse hex range from author {:?}", auth); + } + } + } + // take each author and convert to a hexsearch + let mut del_searches: Vec = vec![]; + for auth in authvec { + match hex_range(auth) { + Some(HexSearch::Exact(ex)) => { + del_searches.push("delegated_by=?".to_owned()); + params.push(Box::new(ex)); + } + Some(HexSearch::Range(lower, upper)) => { + del_searches.push( + "(delegated_by>? AND delegated_by { + del_searches.push("delegated_by>?".to_owned()); params.push(Box::new(lower)); } None => { @@ -553,13 +573,12 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec>) { } } if !authvec.is_empty() { - let authors_clause = format!("({})", auth_searches.join(" OR ")); - filter_components.push(authors_clause); + // combine auth_searches and del_searches + let comb_clause = format!("({} OR {})", auth_searches.join(" OR "), del_searches.join(" OR ")); + filter_components.push(comb_clause); } else { - // if the authors list was empty, we should never return - // any results. - filter_components.push("false".to_owned()); - } + filter_components.push("false".to_owned()); + } } // Query for Kind if let Some(ks) = &f.kinds {