Skip to content

Commit

Permalink
Indexing empty strings and binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
katyo committed Oct 27, 2018
1 parent 11c51ca commit 93f55cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 1 addition & 4 deletions ledb/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,7 @@ fn extract_field_primitives(doc: &Value, typ: KeyType, keys: &mut HashSet<KeyDat
(typ, val) => {
if let Some(val) = KeyData::from_val(&val) {
if let Some(val) = val.into_type(typ) {
// prevent indexing empty values
if !val.is_empty() {
keys.insert(val.into_owned());
}
keys.insert(val.into_owned());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ledb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ mod tests {
mk_index(&c).unwrap();
fill_data(&c).unwrap();

assert_eq!(query!(find Value in c order by s >).unwrap().len(), 6);
assert_found!(query!(find in c order by s >), 3, 5, 6, 1, 2, 4);
assert_found!(query!(find in c order by s <), 4, 2, 1, 6, 5, 3);
assert_eq!(query!(find Value in c order by s >).unwrap().len(), 7);
assert_found!(query!(find in c order by s >), 7, 3, 5, 6, 1, 2, 4);
assert_found!(query!(find in c order by s <), 4, 2, 1, 6, 5, 3, 7);
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions ledb/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ impl KeyData {
match self {
Int(val) => unsafe { transmute::<&i64, &[u8; 8]>(val) },
Float(val) => unsafe { transmute::<&f64, &[u8; 8]>(val) },
String(val) => val.as_bytes(),
Binary(val) => val.as_slice(),
String(val) => if val.is_empty() {
b"\0"
} else {
val.as_bytes()
},
Binary(val) => if val.is_empty() {
&[0u8]
} else {
val.as_slice()
},
Bool(val) => unsafe { transmute::<&bool, &[u8; 1]>(val) },
}
}
Expand Down

0 comments on commit 93f55cc

Please sign in to comment.