Skip to content

Commit

Permalink
Added negation example for filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Dec 9, 2013
1 parent 2bb8b8e commit a168715
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Expand Up @@ -262,8 +262,10 @@ db.search({
}, {
filter: function filter(solution, callback) {
if (solution.x !== 'daniele') {
// confirm the solution
callback(null, solution);
} else {
// refute the solution
callback(null);
}
}
Expand All @@ -273,6 +275,39 @@ db.search({
});
```

Thanks to solultion filtering, it is possible to implement a negation:
```
db.search({
subject: 'matteo'
, predicate: 'friend'
, object: db.v('x')
}, {
filter: function filter(solution, callback) {
db.get({
subject: solution.x
, predicate: 'friend'
, object: 'marco'
}, function (err, results) {
if (err) {
callback(err);
return;
}
if (results.length > 0) {
// confirm the solution
callback(null, solution);
} else {
// refute the solution
callback();
}
});
}
}, function process(err, solutions) {
// results will not contain any solutions that
// do not satisfy the filter
});
```
```
The heavier method is filtering solutions, so we recommend filtering the
triples whenever possible.
Expand Down

0 comments on commit a168715

Please sign in to comment.