-
Notifications
You must be signed in to change notification settings - Fork 766
fix(fts): do not count empty documents in num_docs #7745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,10 +402,18 @@ async fn test_create_fts_index_with_empty_strings() { | |
| false, | ||
| )])); | ||
|
|
||
| // Mix documents that produce tokens with ones that tokenize to nothing | ||
| // (empty and whitespace-only strings). The latter carry no searchable | ||
| // content and must not be counted in `num_docs`. | ||
| let batches: Vec<RecordBatch> = vec![ | ||
| RecordBatch::try_new( | ||
| schema.clone(), | ||
| vec![Arc::new(StringArray::from(vec!["", "", ""]))], | ||
| vec![Arc::new(StringArray::from(vec![ | ||
| "lance", | ||
| "", | ||
| "lance database", | ||
| " ", | ||
| ]))], | ||
| ) | ||
| .unwrap(), | ||
|
Comment on lines
408
to
418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Use The changed test still manually constructs the schema, 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| ]; | ||
|
|
@@ -420,13 +428,33 @@ async fn test_create_fts_index_with_empty_strings() { | |
| .await | ||
| .unwrap(); | ||
|
|
||
| // Only the two token-producing rows are indexed; the empty and | ||
| // whitespace-only rows are skipped so they do not inflate BM25 statistics. | ||
| let stats: serde_json::Value = | ||
| serde_json::from_str(&dataset.index_statistics("text_idx").await.unwrap()).unwrap(); | ||
| assert_eq!( | ||
| stats["indices"][0]["num_docs"], 2, | ||
| "empty documents must not count: {stats}" | ||
| ); | ||
|
|
||
| // The token-producing rows remain searchable. | ||
| let batch = dataset | ||
| .scan() | ||
| .full_text_search(FullTextSearchQuery::new("lance".to_owned())) | ||
| .unwrap() | ||
| .try_into_batch() | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(batch.num_rows(), 2); | ||
|
|
||
| // A term present in no document returns nothing. | ||
| let batch = dataset | ||
| .scan() | ||
| .full_text_search(FullTextSearchQuery::new("missing".to_owned())) | ||
| .unwrap() | ||
| .try_into_batch() | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(batch.num_rows(), 0); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: lance-format/lance
Length of output: 43487
🏁 Script executed:
Repository: lance-format/lance
Length of output: 9394
Add an all-empty regression case.
The empty-table search path is already covered, but this fixture still doesn’t assert the
num_docs == 0BM25/statistics path. Keep a dedicated case for an index built only from empty/whitespace strings if that behavior is part of the regression target.🤖 Prompt for AI Agents