Skip to content

Commit

Permalink
Fast-field based implementation of ExistsQuery
Browse files Browse the repository at this point in the history
Adds an implementation of ExistsQuery that takes advantage of fast fields.

Fixes #2159

Co-authored-by: Paul Masurel <[email protected]>
  • Loading branch information
imotov and fulmicoton committed Sep 1, 2023
1 parent 49448b3 commit 738d146
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/fastfield/readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ impl FastFieldReaders {
Ok(dynamic_column_handle_opt)
}

/// Returning all `dynamic_column_handle`.
pub fn dynamic_column_handles(
&self,
field_name: &str,
) -> crate::Result<Vec<DynamicColumnHandle>> {
let Some(resolved_field_name) = self.resolve_field(field_name)? else {
return Ok(Vec::new());
};
let dynamic_column_handles = self
.columnar
.read_columns(&resolved_field_name)?
.into_iter()
.collect();
Ok(dynamic_column_handles)
}

#[doc(hidden)]
pub async fn list_dynamic_column_handles(
&self,
Expand Down Expand Up @@ -338,6 +354,8 @@ impl FastFieldReaders {

#[cfg(test)]
mod tests {
use columnar::ColumnType;

use crate::schema::{JsonObjectOptions, Schema, FAST};
use crate::{Document, Index};

Expand Down Expand Up @@ -417,4 +435,45 @@ mod tests {
Some("_dyna\u{1}notinschema\u{1}attr\u{1}color".to_string())
);
}

#[test]
fn test_fast_field_reader_dynamic_column_handles() {
let mut schema_builder = Schema::builder();
let id = schema_builder.add_u64_field("id", FAST);
let json = schema_builder.add_json_field("json", FAST);
let schema = schema_builder.build();
let index = Index::create_in_ram(schema);
let mut index_writer = index.writer_for_tests().unwrap();
index_writer
.add_document(doc!(id=> 1u64, json => json!({"foo": 42})))
.unwrap();
index_writer
.add_document(doc!(id=> 2u64, json => json!({"foo": true})))
.unwrap();
index_writer
.add_document(doc!(id=> 3u64, json => json!({"foo": "bar"})))
.unwrap();
index_writer.commit().unwrap();
let reader = index.reader().unwrap();
let searcher = reader.searcher();
let reader = searcher.segment_reader(0u32);
let fast_fields = reader.fast_fields();
let id_columns = fast_fields.dynamic_column_handles("id").unwrap();
assert_eq!(id_columns.len(), 1);
assert_eq!(id_columns.first().unwrap().column_type(), ColumnType::U64);

let foo_columns = fast_fields.dynamic_column_handles("json.foo").unwrap();
assert_eq!(foo_columns.len(), 3);
assert!(foo_columns
.iter()
.any(|column| column.column_type() == ColumnType::I64));
assert!(foo_columns
.iter()
.any(|column| column.column_type() == ColumnType::Bool));
assert!(foo_columns
.iter()
.any(|column| column.column_type() == ColumnType::Str));

println!("*** {:?}", fast_fields.columnar().list_columns());
}
}
Loading

0 comments on commit 738d146

Please sign in to comment.