Skip to content

Commit

Permalink
CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Feb 16, 2023
1 parent 5e51fd1 commit 72e4875
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/fastfield/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,12 @@ mod tests {
let searcher = index.reader().unwrap().searcher();
let segment_reader = searcher.segment_reader(0u32);
let fast_fields = segment_reader.fast_fields();
let column_without_opt: Option<StrColumn> = fast_fields.str("without.hello").unwrap();
let column_without_opt: Option<StrColumn> = fast_fields.str("without\u{1}hello").unwrap();
assert!(column_without_opt.is_none());
let column_with_opt: Option<StrColumn> = fast_fields.str("with.hello").unwrap();
for (col_name, _) in fast_fields.columnar().list_columns().unwrap() {
dbg!(&col_name);
}
let column_with_opt: Option<StrColumn> = fast_fields.str("with\u{1}hello").unwrap();
let column_with: StrColumn = column_with_opt.unwrap();
assert!(column_with.term_ords(0).next().is_none());
assert!(column_with.term_ords(1).eq([0]));
Expand Down
22 changes: 10 additions & 12 deletions src/fastfield/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ impl FastFieldsWriter {
}
Value::JsonObject(json_obj) => {
let expand_dots = self.expand_dots[field_value.field().field_id() as usize];
self.json_path_buffer.clear();
self.json_path_buffer.push_str(field_name);
record_json_obj_to_columnar_writer(
doc_id,
json_obj,
Expand Down Expand Up @@ -209,7 +211,7 @@ fn record_json_obj_to_columnar_writer(
doc: DocId,
json_obj: &serde_json::Map<String, serde_json::Value>,
expand_dots: bool,
depth_limit: usize,
remaining_depth_limit: usize,
json_path_buffer: &mut String,
columnar_writer: &mut columnar::ColumnarWriter,
) {
Expand All @@ -233,7 +235,7 @@ fn record_json_obj_to_columnar_writer(
doc,
child,
expand_dots,
depth_limit,
remaining_depth_limit,
json_path_buffer,
columnar_writer,
);
Expand All @@ -246,14 +248,14 @@ fn record_json_value_to_columnar_writer(
doc: DocId,
json_val: &serde_json::Value,
expand_dots: bool,
mut depth_limit: usize,
mut remaining_depth_limit: usize,
json_path_writer: &mut String,
columnar_writer: &mut columnar::ColumnarWriter,
) {
if depth_limit == 0 {
if remaining_depth_limit == 0 {
return;
}
depth_limit -= 1;
remaining_depth_limit -= 1;
match json_val {
serde_json::Value::Null => {
// TODO handle null
Expand All @@ -275,7 +277,7 @@ fn record_json_value_to_columnar_writer(
doc,
el,
expand_dots,
depth_limit,
remaining_depth_limit,
json_path_writer,
columnar_writer,
);
Expand All @@ -286,7 +288,7 @@ fn record_json_value_to_columnar_writer(
doc,
json_obj,
expand_dots,
depth_limit,
remaining_depth_limit,
json_path_writer,
columnar_writer,
);
Expand Down Expand Up @@ -382,11 +384,7 @@ mod tests {
let columnar_reader = test_columnar_from_jsons_aux(&[json_doc], false);
let columns = columnar_reader.list_columns().unwrap();
assert_eq!(columns.len(), 1);
assert_eq!(
columns[0].0,
"a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\u{1}a\\
u{1}a\u{1}a\u{1}a\u{1}a\u{1}depth_accepted"
);
assert!(columns[0].0.ends_with("a\u{1}a\u{1}a\u{1}depth_accepted"));
}

#[test]
Expand Down
24 changes: 24 additions & 0 deletions src/schema/json_object_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ pub struct JsonObjectOptions {
indexing: Option<TextFieldIndexing>,
// Store all field as fast fields.
fast: bool,
/// tantivy will generate pathes to the different nodes of the json object
/// both in:
/// - the inverted index (for the terms)
/// - fast fields (for the column names).
///
/// These json path are encoded by concatenating the list of object keys that
/// are visited from the root to the leaf.
///
/// By default, if an object key contains a `.`, we keep it as a `.` it as is.
/// On the search side, users will then have to escape this `.` in the query parser
/// or when refering to a column name.
///
/// For instance:
/// `{"root": {"child.with.dot": "hello"}}`
///
/// Can be searched using the following query
/// `root.child\.with\.dot:hello`
///
/// If `expand_dots_enabled` is set to true, we will treat this `.` in object keys
/// as json seperators. In other words, if set to true, our object will be
/// processed as if it was
/// `{"root": {"child": {"with": {"dot": "hello"}}}}`
/// and it can be search using the following query:
/// `root.child.with.dot:hello`
expand_dots_enabled: bool,
}

Expand Down

0 comments on commit 72e4875

Please sign in to comment.