Skip to content

Commit

Permalink
A hopefully simpler query language
Browse files Browse the repository at this point in the history
An alternative to #140 that doesn't use sikula, somewhat based on the
proposal described in #9. OR and AND conditions aren't yet supported
-- all filters passed are AND'ed -- but any field of an Entity can be
used for either filtering or sorting without needing to introduce new
abstractions.

Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 committed Apr 8, 2024
1 parent 36440c1 commit 5a3fc74
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 149 deletions.
91 changes: 2 additions & 89 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ serde = "1.0.183"
serde_json = "1.0.114"
serde_yaml = "0.9"
sha2 = "0.10.8"
sikula = "0.4.4"
spdx-expression = "0.5.2"
spdx-rs = "0.5.3"
sqlx = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion modules/search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ actix-web = { workspace = true }
anyhow = { workspace = true }
csaf = { workspace = true }
log = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
sea-orm = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sikula = { workspace = true, features = ["sea-orm"] }
thiserror = { workspace = true }
time = { workspace = true }
tokio = { workspace = true, features = ["full"] }
Expand Down
8 changes: 3 additions & 5 deletions modules/search/src/endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::model::{AdvisorySearch, SearchOptions};
use crate::model::SearchOptions;
use crate::service::{Error, SearchService};
use actix_web::{get, web, Responder};
use sikula::prelude::Search;
use trustify_common::db::Database;
use trustify_common::model::Paginated;
use utoipa::OpenApi;
Expand Down Expand Up @@ -29,12 +28,11 @@ pub struct ApiDoc;
#[get("/advisory")]
/// Search for advisories
async fn search_advisories(
web::Query(SearchOptions { q }): web::Query<SearchOptions>,
web::Query(SearchOptions { q, sort }): web::Query<SearchOptions>,
web::Query(paginated): web::Query<Paginated>,
service: web::Data<SearchService>,
) -> Result<impl Responder, Error> {
let search = AdvisorySearch::parse(&q)?;
Ok(web::Json(
service.search_advisories(search, paginated).await?,
service.search_advisories(q, sort, paginated).await?,
))
}
2 changes: 2 additions & 0 deletions modules/search/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pub mod endpoints;
pub mod model;
pub mod service;

pub mod query;
14 changes: 2 additions & 12 deletions modules/search/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use sikula::prelude::*;
use time::OffsetDateTime;
use trustify_common::model::PaginatedResults;
use trustify_entity::advisory;
Expand All @@ -8,17 +7,8 @@ use trustify_entity::advisory;
pub struct SearchOptions {
#[serde(default)]
pub q: String,
}

#[derive(Debug, sikula::Search)]
pub enum AdvisorySearch<'a> {
#[search(scope, default)]
Title(Primary<'a>),

#[search(sort)]
Modified(Ordered<OffsetDateTime>),
#[search(sort)]
Published(Ordered<OffsetDateTime>),
#[serde(default)]
pub sort: String,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
Expand Down
Loading

0 comments on commit 5a3fc74

Please sign in to comment.