aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/core/query.cc
diff options
context:
space:
mode:
authorrsgowman <rgowman@google.com>2018-07-13 16:22:07 -0400
committerGitHub <noreply@github.com>2018-07-13 16:22:07 -0400
commit920cfbfa998ca9d04cce5f7731aced7e950a3477 (patch)
tree76f62fa05240d533477707bb4cd26df6808cd523 /Firestore/core/src/firebase/firestore/core/query.cc
parent81ec26d4ff2f9cc295bf057167a649a34a7a11aa (diff)
Initial (incomplete) implementation of f:f:core::Filter (#1495)
And RelationFilter subclass. Used to implement the next step in core::Query.
Diffstat (limited to 'Firestore/core/src/firebase/firestore/core/query.cc')
-rw-r--r--Firestore/core/src/firebase/firestore/core/query.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/Firestore/core/src/firebase/firestore/core/query.cc b/Firestore/core/src/firebase/firestore/core/query.cc
index ad0f7a3..0c0a0fd 100644
--- a/Firestore/core/src/firebase/firestore/core/query.cc
+++ b/Firestore/core/src/firebase/firestore/core/query.cc
@@ -16,8 +16,12 @@
#include "Firestore/core/src/firebase/firestore/core/query.h"
+#include <algorithm>
+
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_path.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
+#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
namespace firebase {
namespace firestore {
@@ -41,9 +45,11 @@ bool Query::MatchesPath(const Document& doc) const {
}
}
-bool Query::MatchesFilters(const Document&) const {
- // TODO(rsgowman): Implement this correctly.
- return true;
+bool Query::MatchesFilters(const Document& doc) const {
+ return std::all_of(filters_.begin(), filters_.end(),
+ [&](const std::shared_ptr<core::Filter>& filter) {
+ return filter->Matches(doc);
+ });
}
bool Query::MatchesOrderBy(const Document&) const {
@@ -56,6 +62,18 @@ bool Query::MatchesBounds(const Document&) const {
return true;
}
+Query Query::Filter(std::shared_ptr<core::Filter> filter) const {
+ HARD_ASSERT(!DocumentKey::IsDocumentKey(path_),
+ "No filter is allowed for document query");
+
+ // TODO(rsgowman): ensure only one inequality field
+ // TODO(rsgowman): ensure first orderby must match inequality field
+
+ std::vector<std::shared_ptr<core::Filter>> updated_filters = filters_;
+ updated_filters.push_back(std::move(filter));
+ return Query(path_, std::move(updated_filters));
+}
+
} // namespace core
} // namespace firestore
} // namespace firebase