Skip to content

Commit

Permalink
[db] Fix path condition not adding element when it should #833 (#834)
Browse files Browse the repository at this point in the history
fix distance less than or equal
  • Loading branch information
michaelvlach authored Dec 8, 2023
1 parent 0b4987d commit 2550ce5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions agdb/src/query/query_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ impl CountComparison {
}
},
CountComparison::LessThanOrEqual(left) => match right.cmp(left) {
std::cmp::Ordering::Less => SearchControl::Continue(true),
std::cmp::Ordering::Equal => SearchControl::Stop(true),
std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {
SearchControl::Continue(true)
}
std::cmp::Ordering::Greater => SearchControl::Stop(false),
},
CountComparison::NotEqual(left) => match right.cmp(left) {
Expand Down Expand Up @@ -329,7 +330,7 @@ mod tests {
assert_eq!(LessThan(2).compare_distance(2), Stop(false));
assert_eq!(LessThan(2).compare_distance(1), Continue(true));
assert_eq!(LessThanOrEqual(2).compare_distance(3), Stop(false));
assert_eq!(LessThanOrEqual(2).compare_distance(2), Stop(true));
assert_eq!(LessThanOrEqual(2).compare_distance(2), Continue(true));
assert_eq!(LessThanOrEqual(2).compare_distance(1), Continue(true));
}

Expand Down
14 changes: 14 additions & 0 deletions agdb/tests/search_where_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,17 @@ fn search_from_where_key_value_contains() {
&[8],
);
}

#[test]
fn search_path_with_distance() {
let db = create_db();
db.exec_ids(
QueryBuilder::search()
.from("root")
.to("users")
.where_()
.distance(CountComparison::LessThanOrEqual(2))
.query(),
&[1, -4, 2],
);
}

0 comments on commit 2550ce5

Please sign in to comment.