Skip to content

Commit

Permalink
fix: full text search index may be corrupted after remapping (#3388)
Browse files Browse the repository at this point in the history
the posting lists must be written in the original order

---------

Signed-off-by: BubbleCal <[email protected]>
  • Loading branch information
BubbleCal authored Jan 16, 2025
1 parent 4149457 commit 62a2256
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rust/lance-index/src/scalar/inverted/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ impl InvertedIndexBuilder {
Result::Ok((batch, max_score))
}
});
let mut stream =
stream::iter(batches).buffer_unordered(get_num_compute_intensive_cpus());
let mut stream = stream::iter(batches).buffered(get_num_compute_intensive_cpus());
let mut offsets = Vec::new();
let mut max_scores = Vec::new();
let mut num_rows = 0;
Expand Down
27 changes: 27 additions & 0 deletions rust/lance/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ impl DatasetIndexInternalExt for Dataset {
#[cfg(test)]
mod tests {
use crate::dataset::builder::DatasetBuilder;
use crate::dataset::optimize::{compact_files, CompactionOptions};
use crate::utils::test::{DatagenExt, FragmentCount, FragmentRowCount};

use super::*;
Expand Down Expand Up @@ -1556,6 +1557,32 @@ mod tests {

assert_eq!(texts.len(), 1, "query: {}, texts: {:?}", word, texts);
assert_eq!(texts[0], word, "query: {}, texts: {:?}", word, texts);

// we should be able to query the new words after compaction
compact_files(&mut dataset, CompactionOptions::default(), None)
.await
.unwrap();
for &word in uppercase_words.iter() {
let query_result = dataset
.scan()
.project(&["text"])
.unwrap()
.full_text_search(FullTextSearchQuery::new(word.to_string()))
.unwrap()
.try_into_batch()
.await
.unwrap();
let texts = query_result["text"]
.as_string::<i32>()
.iter()
.map(|v| match v {
None => "".to_string(),
Some(v) => v.to_string(),
})
.collect::<Vec<String>>();
assert_eq!(texts.len(), 1, "query: {}, texts: {:?}", word, texts);
assert_eq!(texts[0], word, "query: {}, texts: {:?}", word, texts);
}
}
}

Expand Down

0 comments on commit 62a2256

Please sign in to comment.