Skip to content

Commit

Permalink
feat: upgrade to tantivy 0.20
Browse files Browse the repository at this point in the history
Also workaround for #283 until panic in tantivy is diagnosed
  • Loading branch information
Ulf Lilleengen committed Aug 30, 2023
1 parent 2dccd85 commit 70afb82
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 108 deletions.
152 changes: 94 additions & 58 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ default-members = [
]

[patch.crates-io]
#tantivy = { path = "../tantivy" }
#sikula = { git = "https://github.com/ctron/sikula", rev = "cea7429f6b690adcdcd1ce2edb2b9e2277834e03" }
#sikula = { path = "../sikula" }

Expand Down
2 changes: 1 addition & 1 deletion bombastic/index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
sikula = { version = "0.4.0-alpha.5", features = ["time"] }
zstd = "0.12"
tantivy = { version = "0.19.2", features = ["zstd-compression"] }
tantivy = { version = "0.20.2", features = ["zstd-compression"] }
log = "0.4"
time = "0.3"
tar = "0.4"
Expand Down
26 changes: 16 additions & 10 deletions bombastic/index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tantivy::{
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use trustification_api::search::SearchOptions;
use trustification_index::{
boost, create_boolean_query, create_date_query, create_string_query, create_text_query, field2str,
boost, create_boolean_query, create_date_query, create_string_query, field2str,
metadata::doc2metadata,
tantivy::{
doc,
Expand Down Expand Up @@ -340,13 +340,23 @@ impl Index {
value,
)])),

Packages::Created(ordered) => boost(create_date_query(self.fields.sbom_created, ordered), CREATED_WEIGHT),
Packages::Created(ordered) => boost(
create_date_query(
self.fields.sbom_created,
self.schema.get_field_name(self.fields.sbom_created),
ordered,
),
CREATED_WEIGHT,
),

Packages::Version(value) => {
self.create_string_query(&[self.fields.sbom.version, self.fields.sbom.purl_version], value)
}

Packages::Description(primary) => self.create_text_query(&[self.fields.sbom.desc], primary),
Packages::Description(value) => Box::new(TermSetQuery::new(vec![Term::from_field_text(
self.fields.sbom.desc,
value,
)])),

Packages::Digest(value) => Box::new(TermSetQuery::new(vec![Term::from_field_text(
self.fields.sbom.sha256,
Expand Down Expand Up @@ -396,11 +406,6 @@ impl Index {
Box::new(BooleanQuery::union(queries))
}

fn create_text_query(&self, fields: &[Field], value: &Primary<'_>) -> Box<dyn Query> {
let queries: Vec<Box<dyn Query>> = fields.iter().map(|f| create_text_query(*f, value)).collect();
Box::new(BooleanQuery::union(queries))
}

fn match_classifiers(&self, classification: Classification) -> Box<dyn Query> {
Box::new(BooleanQuery::union(vec![
create_boolean_query(
Expand Down Expand Up @@ -467,7 +472,7 @@ impl trustification_index::Index for Index {

query.term = query.term.compact();

debug!("Query: {query:?}");
debug!("Query: {:?}", query.term);

let mut sort_by = None;
if let Some(f) = query.sorting.first() {
Expand Down Expand Up @@ -497,6 +502,7 @@ impl trustification_index::Index for Index {
limit: usize,
) -> Result<(Vec<(f32, DocAddress)>, usize), SearchError> {
if let Some(order_by) = query.sort_by {
let order_by = self.schema.get_field_name(order_by);
let mut hits = Vec::new();
let result = searcher.search(
&query.query,
Expand Down Expand Up @@ -844,7 +850,7 @@ mod tests {
assert_search(|index| {
let result = index
.search(
"dependency:openssl",
"(ubi in:package) OR (ubi in:description)",
0,
10000,
SearchOptions {
Expand Down
2 changes: 1 addition & 1 deletion bombastic/model/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum Packages<'a> {
#[search(default)]
Version(Primary<'a>),
#[search(default)]
Description(Primary<'a>),
Description(&'a str),
#[search(sort)]
Created(Ordered<time::OffsetDateTime>),
Digest(&'a str),
Expand Down

0 comments on commit 70afb82

Please sign in to comment.