Skip to content

Commit

Permalink
feat: add predicates/field for severity
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Oct 10, 2023
1 parent 7c1a5da commit 7d742f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions v11y/index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use cvss::v3::Base;
use cvss::Severity;
use sikula::prelude::*;
use tantivy::{
collector::TopDocs, query::AllQuery, schema::INDEXED, store::ZstdCompressor, DocAddress, IndexSettings, Order,
Searcher,
collector::TopDocs,
query::{AllQuery, TermQuery},
schema::INDEXED,
store::ZstdCompressor,
DocAddress, IndexSettings, Order, Searcher,
};
use time::OffsetDateTime;
use trustification_api::search::SearchOptions;
Expand Down Expand Up @@ -168,6 +171,10 @@ impl Index {
Cves::Published => create_boolean_query(Occur::Should, Term::from_field_bool(self.fields.published, true)),
Cves::Rejected => create_boolean_query(Occur::Should, Term::from_field_bool(self.fields.published, false)),

Cves::Severity(value) => Box::new(TermQuery::new(
Term::from_field_text(self.fields.severity, value),
Default::default(),
)),
Cves::Low => create_boolean_query(
Occur::Should,
Term::from_field_text(self.fields.severity, Severity::Low.as_str()),
Expand Down
2 changes: 1 addition & 1 deletion v11y/model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.68"
utoipa = { version = "3", features = ["actix_extras"] }
sikula = { version = "0.4.1", default-features = false, features = ["time"] }
time = { version = "0.3", features = ["serde"] }
time = { version = "0.3", features = ["serde", "formatting", "parsing"] }
5 changes: 5 additions & 0 deletions v11y/model/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub enum Cves<'a> {
#[search(sort)]
DateRejected(Ordered<OffsetDateTime>),

Low,
Medium,
High,
Critical,

Published,
Rejected,
}
Expand Down

0 comments on commit 7d742f4

Please sign in to comment.