Skip to content

Commit 1932513

Browse files
authored
Fast-field based implementation of ExistsQuery (#2160)
Adds an implementation of ExistsQuery that takes advantage of fast fields. Fixes #2159
1 parent 389d36f commit 1932513

File tree

3 files changed

+406
-0
lines changed

3 files changed

+406
-0
lines changed

src/fastfield/readers.rs

+59
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ impl FastFieldReaders {
234234
Ok(dynamic_column_handle_opt)
235235
}
236236

237+
/// Returning all `dynamic_column_handle`.
238+
pub fn dynamic_column_handles(
239+
&self,
240+
field_name: &str,
241+
) -> crate::Result<Vec<DynamicColumnHandle>> {
242+
let Some(resolved_field_name) = self.resolve_field(field_name)? else {
243+
return Ok(Vec::new());
244+
};
245+
let dynamic_column_handles = self
246+
.columnar
247+
.read_columns(&resolved_field_name)?
248+
.into_iter()
249+
.collect();
250+
Ok(dynamic_column_handles)
251+
}
252+
237253
#[doc(hidden)]
238254
pub async fn list_dynamic_column_handles(
239255
&self,
@@ -338,6 +354,8 @@ impl FastFieldReaders {
338354

339355
#[cfg(test)]
340356
mod tests {
357+
use columnar::ColumnType;
358+
341359
use crate::schema::{JsonObjectOptions, Schema, FAST};
342360
use crate::{Document, Index};
343361

@@ -417,4 +435,45 @@ mod tests {
417435
Some("_dyna\u{1}notinschema\u{1}attr\u{1}color".to_string())
418436
);
419437
}
438+
439+
#[test]
440+
fn test_fast_field_reader_dynamic_column_handles() {
441+
let mut schema_builder = Schema::builder();
442+
let id = schema_builder.add_u64_field("id", FAST);
443+
let json = schema_builder.add_json_field("json", FAST);
444+
let schema = schema_builder.build();
445+
let index = Index::create_in_ram(schema);
446+
let mut index_writer = index.writer_for_tests().unwrap();
447+
index_writer
448+
.add_document(doc!(id=> 1u64, json => json!({"foo": 42})))
449+
.unwrap();
450+
index_writer
451+
.add_document(doc!(id=> 2u64, json => json!({"foo": true})))
452+
.unwrap();
453+
index_writer
454+
.add_document(doc!(id=> 3u64, json => json!({"foo": "bar"})))
455+
.unwrap();
456+
index_writer.commit().unwrap();
457+
let reader = index.reader().unwrap();
458+
let searcher = reader.searcher();
459+
let reader = searcher.segment_reader(0u32);
460+
let fast_fields = reader.fast_fields();
461+
let id_columns = fast_fields.dynamic_column_handles("id").unwrap();
462+
assert_eq!(id_columns.len(), 1);
463+
assert_eq!(id_columns.first().unwrap().column_type(), ColumnType::U64);
464+
465+
let foo_columns = fast_fields.dynamic_column_handles("json.foo").unwrap();
466+
assert_eq!(foo_columns.len(), 3);
467+
assert!(foo_columns
468+
.iter()
469+
.any(|column| column.column_type() == ColumnType::I64));
470+
assert!(foo_columns
471+
.iter()
472+
.any(|column| column.column_type() == ColumnType::Bool));
473+
assert!(foo_columns
474+
.iter()
475+
.any(|column| column.column_type() == ColumnType::Str));
476+
477+
println!("*** {:?}", fast_fields.columnar().list_columns());
478+
}
420479
}

0 commit comments

Comments
 (0)