diff --git a/src/config/src/meta/inverted_index/search.rs b/src/config/src/meta/inverted_index/search.rs index 8213f796a3..002be6f643 100644 --- a/src/config/src/meta/inverted_index/search.rs +++ b/src/config/src/meta/inverted_index/search.rs @@ -14,9 +14,9 @@ pub struct SubstringSearch<'b> { } impl<'b> SubstringSearch<'b> { - pub async fn new(terms: &Vec, 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, meta: &'b ColumnIndexMeta) -> Self { + pub fn new(terms: &[String], meta: &'b ColumnIndexMeta) -> Self { ExactSearch { - terms: terms.clone(), + terms: terms.to_owned(), meta, } } diff --git a/src/config/src/utils/inverted_index.rs b/src/config/src/utils/inverted_index.rs index 44b7618ae9..ff3dffb509 100644 --- a/src/config/src/utils/inverted_index.rs +++ b/src/config/src/utils/inverted_index.rs @@ -129,6 +129,12 @@ mod tests { assert_eq!(result, Vec::::new()); } + #[test] + fn test_min_character() { + let result = split_token("t", ""); + assert_eq!(result, Vec::::new()); + } + #[test] fn test_empty_delimiter() { let result = split_token("Hello, world! This is a test.", ""); diff --git a/src/service/search/cluster/mod.rs b/src/service/search/cluster/mod.rs index 77085de013..8045846c71 100644 --- a/src/service/search/cluster/mod.rs +++ b/src/service/search/cluster/mod.rs @@ -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::>(); @@ -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::>(); @@ -1049,12 +1055,17 @@ async fn get_file_list_by_inverted_index( }) .collect::>(); 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") {