Skip to content

Commit

Permalink
Fix indexing for bool
Browse files Browse the repository at this point in the history
  • Loading branch information
boraarslan committed Jun 2, 2022
1 parent 7880243 commit 499e25c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/indexer/json_term_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ fn index_json_value<'a>(
match json_value {
serde_json::Value::Null => {}
serde_json::Value::Bool(val_bool) => {
let bool_u64 = if *val_bool { 1u64 } else { 0u64 };
json_term_writer.set_fast_value(bool_u64);
json_term_writer.set_fast_value(*val_bool);
postings_writer.subscribe(doc, 0u32, json_term_writer.term(), ctx);
}
serde_json::Value::Number(number) => {
Expand Down Expand Up @@ -220,6 +219,9 @@ pub(crate) fn convert_to_fast_value_and_get_term(
if let Ok(f64_val) = str::parse::<f64>(phrase) {
return Some(set_fastvalue_and_get_term(json_term_writer, f64_val));
}
if let Ok(bool_val) = str::parse::<bool>(phrase) {
return Some(set_fastvalue_and_get_term(json_term_writer, bool_val));
}
None
}
// helper function to generate a Term from a json fastvalue
Expand Down Expand Up @@ -434,6 +436,20 @@ mod tests {
)
}

#[test]
fn test_bool_term() {
let field = Field::from_field_id(1);
let mut term = Term::new();
term.set_field(Type::Json, field);
let mut json_writer = JsonTermWriter::wrap(&mut term);
json_writer.push_path_segment("color");
json_writer.set_fast_value(true);
assert_eq!(
json_writer.term().as_slice(),
b"\x00\x00\x00\x01jcolor\x00o\x00\x00\x00\x00\x00\x00\x00\x01"
)
}

#[test]
fn test_push_after_set_path_segment() {
let field = Field::from_field_id(1);
Expand Down

0 comments on commit 499e25c

Please sign in to comment.