Compare commits

...

1 Commits

Author SHA1 Message Date
YoEight
6ce8a5726a Fix empty index crashing when searching attributes 2025-12-18 08:26:59 -05:00
3 changed files with 33 additions and 0 deletions

View File

@@ -178,6 +178,12 @@ impl<'ctx> SearchContext<'ctx> {
None if user_defined_searchable.is_none() => continue, None if user_defined_searchable.is_none() => continue,
// The field is not searchable => User error // The field is not searchable => User error
None => { None => {
if let Some(defined_searchable) = &user_defined_searchable {
if defined_searchable.iter().any(|s| s == field_name) {
continue;
}
}
let (valid_fields, hidden_fields) = self.index.remove_hidden_fields( let (valid_fields, hidden_fields) = self.index.remove_hidden_fields(
self.txn, self.txn,
searchable_fields_weights.iter().map(|(name, _, _)| name), searchable_fields_weights.iter().map(|(name, _, _)| name),

View File

@@ -0,0 +1,26 @@
use crate::index::tests::TempIndex;
use crate::Search;
fn create_empty_index() -> TempIndex {
let index = TempIndex::new();
index.update_settings(|s| {
s.set_primary_key("id".to_string());
s.set_searchable_fields(vec!["name".to_string(), "title".to_string()]);
}).unwrap();
index
}
#[test]
fn test_attribute_search_on_empty_index() {
let index = create_empty_index();
let txn = index.read_txn().unwrap();
let mut search = Search::new(&txn, &index);
let attrs= ["title".to_string()];
search.searchable_attributes(&attrs);
search.query("doc");
search.execute().unwrap();
}

View File

@@ -16,6 +16,7 @@ pub mod stop_words;
pub mod typo; pub mod typo;
pub mod typo_proximity; pub mod typo_proximity;
pub mod words_tms; pub mod words_tms;
mod attribute_update;
fn collect_field_values( fn collect_field_values(
index: &crate::Index, index: &crate::Index,