Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add in-depth guide #611 #623

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
368 changes: 367 additions & 1 deletion docs/guide.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion docs/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ The currently supported conditions are:

All conditions can be further modified as follows:

- Beyond (continues the search only beyond this element)
- Not (reverses the condition result)
- NotBeyond (stops the search beyond this element)

Expand All @@ -606,6 +607,7 @@ pub enum QueryConditionLogic {

pub enum QueryConditionModifier {
None,
Beyond,
Not,
NotBeyond,
}
Expand Down Expand Up @@ -657,6 +659,7 @@ QueryBuilder::search().from(1).where_().key("k").value(Comparison::Equal(1.into(
QueryBuilder::search().from(1).where_().keys(vec!["k1".into(), "k2".into()]).query();
QueryBuilder::search().from(1).where_().not().keys(vec!["k1".into(), "k2".into()]).query();
QueryBuilder::search().from(1).where_().ids(vec![1, 2]).query();
QueryBuilder::search().from(1).where_().beyond().keys(vec!["k"]).query();
QueryBuilder::search().from(1).where_().not().ids(vec![1, 2]).query();
QueryBuilder::search().from(1).where_().not_beyond().ids("a").query();
QueryBuilder::search().from(1).where_().node().or().edge().query();
Expand All @@ -668,6 +671,6 @@ NOTE: The use of `where_` with an underscore as the method name is necessary to

The conditions are applied one at a time to each visited element and chained using logic operators `AND` and `OR`. They can be nested using `where_` and `end_where` (in place of brackets). The condition evaluator supports short-circuiting not evaluating conditions further if the logical outcome cannot change.

The condition `Distance` and the condition modifier `NotBeyond` are particularly important because they can directly influence the search. The former (`Distance`) can limit the depth of the search and can help with constructing more elaborate queries (or sequence thereof) extracting only fine grained elements (e.g. nodes whose edges have particular properties or are connected to other nodes with some properties). The latter (`NotBeyond`) can limit search to only certain areas of an otherwise larger graph. Its most basic usage would be with condition `ids` to flat out stop the search at certain elements.
The condition `Distance` and the condition modifiers `Beyond` and `NotBeyond` are particularly important because they can directly influence the search. The former (`Distance`) can limit the depth of the search and can help with constructing more elaborate queries (or sequence thereof) extracting only fine grained elements (e.g. nodes whose edges have particular properties or are connected to other nodes with some properties). The latter (`Beyond` and `NotBeyond`) can limit search to only certain areas of an otherwise larger graph. Its most basic usage would be with condition `ids` to flat out stop the search at certain elements or continue only beyond certain elements.

For further examples and use cases see the [in-depth guide](guide.md).
7 changes: 7 additions & 0 deletions src/agdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,13 @@ impl Db {
let mut control = self.evaluate_condition(index, distance, &condition.data)?;

match condition.modifier {
QueryConditionModifier::Beyond => {
if control.is_true() {
control = control.and(SearchControl::Continue(true));
} else {
control = SearchControl::Stop(true);
}
}
QueryConditionModifier::Not => control.flip(),
QueryConditionModifier::NotBeyond => {
if control.is_true() {
Expand Down
1 change: 1 addition & 0 deletions src/agdb/query/query_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum QueryConditionModifier {
None,
Not,
NotBeyond,
Beyond,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions src/agdb/query_builder/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ impl SearchTo {
pub fn query(self) -> SearchQuery {
self.0
}

pub fn where_(self) -> Where {
Where::new(self.0)
}
}

impl SelectLimit {
Expand Down
6 changes: 6 additions & 0 deletions src/agdb/query_builder/where_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ impl Where {
}
}

pub fn beyond(mut self) -> Where {
self.modifier = QueryConditionModifier::Beyond;

self
}

pub fn distance(mut self, comparison: CountComparison) -> WhereLogicOperator {
self.add_condition(QueryCondition {
logic: self.logic,
Expand Down
Loading