mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-06 08:09:24 +00:00
fix: match all panic (#4442)
This commit is contained in:
@@ -14,9 +14,9 @@ pub struct SubstringSearch<'b> {
|
||||
}
|
||||
|
||||
impl<'b> SubstringSearch<'b> {
|
||||
pub async fn new(terms: &Vec<String>, meta: &'b ColumnIndexMeta) -> Self {
|
||||
pub async fn new(terms: &[String], meta: &'b ColumnIndexMeta) -> Self {
|
||||
SubstringSearch {
|
||||
terms: terms.clone(),
|
||||
terms: terms.to_owned(),
|
||||
meta,
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ pub struct ExactSearch<'b> {
|
||||
}
|
||||
|
||||
impl<'b> ExactSearch<'b> {
|
||||
pub fn new(terms: &Vec<String>, meta: &'b ColumnIndexMeta) -> Self {
|
||||
pub fn new(terms: &[String], meta: &'b ColumnIndexMeta) -> Self {
|
||||
ExactSearch {
|
||||
terms: terms.clone(),
|
||||
terms: terms.to_owned(),
|
||||
meta,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,12 @@ mod tests {
|
||||
assert_eq!(result, Vec::<String>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_character() {
|
||||
let result = split_token("t", "");
|
||||
assert_eq!(result, Vec::<String>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_delimiter() {
|
||||
let result = split_token("Hello, world! This is a test.", "");
|
||||
|
||||
@@ -996,7 +996,7 @@ async fn get_file_list_by_inverted_index(
|
||||
let cfg = get_config();
|
||||
|
||||
let stream_type = StreamType::from(idx_req.stream_type.as_str());
|
||||
let file_list = file_list
|
||||
let file_list_map = file_list
|
||||
.iter()
|
||||
.map(|f| (&f.key, &f.meta))
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -1005,12 +1005,18 @@ async fn get_file_list_by_inverted_index(
|
||||
let terms = meta
|
||||
.fts_terms
|
||||
.iter()
|
||||
.map(|t| {
|
||||
.filter_map(|t| {
|
||||
let tokens = split_token(t, &cfg.common.inverted_index_split_chars);
|
||||
tokens
|
||||
.into_iter()
|
||||
.max_by_key(|key| key.len())
|
||||
.unwrap_or_default()
|
||||
// If tokens empty return None so terms is empty hashset
|
||||
if tokens.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(
|
||||
tokens
|
||||
.into_iter()
|
||||
.max_by_key(|key| key.len())
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
})
|
||||
.collect::<HashSet<String>>();
|
||||
|
||||
@@ -1049,12 +1055,17 @@ async fn get_file_list_by_inverted_index(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let index_condition = index_terms.join(" OR ");
|
||||
let search_condition = if fts_condition.is_empty() {
|
||||
index_condition
|
||||
} else if index_condition.is_empty() {
|
||||
fts_condition
|
||||
} else {
|
||||
format!("{} OR {}", fts_condition, index_condition)
|
||||
|
||||
// If both empty return original file list with other params as 0
|
||||
let search_condition = match (index_condition.is_empty(), fts_condition.is_empty()) {
|
||||
(true, true) => {
|
||||
return Ok((file_list.to_vec(), 0, 0));
|
||||
}
|
||||
(true, false) => fts_condition,
|
||||
(false, true) => index_condition,
|
||||
_ => {
|
||||
format!("{} OR {}", fts_condition, index_condition)
|
||||
}
|
||||
};
|
||||
|
||||
let index_stream_name =
|
||||
@@ -1104,7 +1115,7 @@ async fn get_file_list_by_inverted_index(
|
||||
"files/{}/{}/{}/{}",
|
||||
meta.org_id, stream_type, meta.stream_name, filename
|
||||
);
|
||||
let Some(file_meta) = file_list.get(&prefixed_filename) else {
|
||||
let Some(file_meta) = file_list_map.get(&prefixed_filename) else {
|
||||
continue;
|
||||
};
|
||||
let segment_ids = match item.get("segment_ids") {
|
||||
|
||||
Reference in New Issue
Block a user