diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-06-19 11:04:17 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-19 11:10:47 +0200 |
commit | 077e3cb30ace5f6ee20ee15e0d32d2bfb197fde0 (patch) | |
tree | 3cfdaf0912ef22dba71755b4332354d579f6e7cf /common/query.h | |
parent | 1ff4456e5dc2b9a9dfa80047f9e5a4a9e1395cdf (diff) | |
download | sink-077e3cb30ace5f6ee20ee15e0d32d2bfb197fde0.tar.gz sink-077e3cb30ace5f6ee20ee15e0d32d2bfb197fde0.zip |
Implement Overlap queries
Summary:
Notes:
- Introduces the concept of queries on multiple properties (which meant changing query's internals a bit)
- Dates are stored as well as the "reference" in the index to allow quick filtering without fetching the whole entity
- Buckets are weeks starting on Monday (guaranteed by the use of the Julian calendar)
- Some size improvements are definitely possible (dates are padded numbers again, not using integer databases, Julian calendar starts at a very old date, etc.)
Test Plan: Tested in querytest
Reviewers: cmollekopf
Reviewed By: cmollekopf
Tags: #sink
Differential Revision: https://phabricator.kde.org/D13477
Diffstat (limited to 'common/query.h')
-rw-r--r-- | common/query.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/common/query.h b/common/query.h index 7130116..cb9c8ca 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -37,6 +37,7 @@ public: | |||
37 | Contains, | 37 | Contains, |
38 | In, | 38 | In, |
39 | Within, | 39 | Within, |
40 | Overlap, | ||
40 | Fulltext | 41 | Fulltext |
41 | }; | 42 | }; |
42 | 43 | ||
@@ -53,7 +54,7 @@ public: | |||
53 | class SINK_EXPORT Filter { | 54 | class SINK_EXPORT Filter { |
54 | public: | 55 | public: |
55 | QByteArrayList ids; | 56 | QByteArrayList ids; |
56 | QHash<QByteArray, Comparator> propertyFilter; | 57 | QHash<QByteArrayList, Comparator> propertyFilter; |
57 | bool operator==(const Filter &other) const; | 58 | bool operator==(const Filter &other) const; |
58 | }; | 59 | }; |
59 | 60 | ||
@@ -64,7 +65,12 @@ public: | |||
64 | 65 | ||
65 | Comparator getFilter(const QByteArray &property) const | 66 | Comparator getFilter(const QByteArray &property) const |
66 | { | 67 | { |
67 | return mBaseFilterStage.propertyFilter.value(property); | 68 | return mBaseFilterStage.propertyFilter.value({property}); |
69 | } | ||
70 | |||
71 | Comparator getFilter(const QByteArrayList &properties) const | ||
72 | { | ||
73 | return mBaseFilterStage.propertyFilter.value(properties); | ||
68 | } | 74 | } |
69 | 75 | ||
70 | template <class T> | 76 | template <class T> |
@@ -73,9 +79,15 @@ public: | |||
73 | return getFilter(T::name); | 79 | return getFilter(T::name); |
74 | } | 80 | } |
75 | 81 | ||
82 | template <class T1, class T2, class... Rest> | ||
83 | Comparator getFilter() const | ||
84 | { | ||
85 | return getFilter({T1::name, T2::name, Rest::name...}); | ||
86 | } | ||
87 | |||
76 | bool hasFilter(const QByteArray &property) const | 88 | bool hasFilter(const QByteArray &property) const |
77 | { | 89 | { |
78 | return mBaseFilterStage.propertyFilter.contains(property); | 90 | return mBaseFilterStage.propertyFilter.contains({property}); |
79 | } | 91 | } |
80 | 92 | ||
81 | template <class T> | 93 | template <class T> |
@@ -94,7 +106,7 @@ public: | |||
94 | return mId; | 106 | return mId; |
95 | } | 107 | } |
96 | 108 | ||
97 | void setBaseFilters(const QHash<QByteArray, Comparator> &filter) | 109 | void setBaseFilters(const QHash<QByteArrayList, Comparator> &filter) |
98 | { | 110 | { |
99 | mBaseFilterStage.propertyFilter = filter; | 111 | mBaseFilterStage.propertyFilter = filter; |
100 | } | 112 | } |
@@ -104,7 +116,7 @@ public: | |||
104 | mBaseFilterStage = filter; | 116 | mBaseFilterStage = filter; |
105 | } | 117 | } |
106 | 118 | ||
107 | QHash<QByteArray, Comparator> getBaseFilters() const | 119 | QHash<QByteArrayList, Comparator> getBaseFilters() const |
108 | { | 120 | { |
109 | return mBaseFilterStage.propertyFilter; | 121 | return mBaseFilterStage.propertyFilter; |
110 | } | 122 | } |
@@ -131,7 +143,12 @@ public: | |||
131 | 143 | ||
132 | void filter(const QByteArray &property, const QueryBase::Comparator &comparator) | 144 | void filter(const QByteArray &property, const QueryBase::Comparator &comparator) |
133 | { | 145 | { |
134 | mBaseFilterStage.propertyFilter.insert(property, comparator); | 146 | mBaseFilterStage.propertyFilter.insert({property}, comparator); |
147 | } | ||
148 | |||
149 | void filter(const QByteArrayList &properties, const QueryBase::Comparator &comparator) | ||
150 | { | ||
151 | mBaseFilterStage.propertyFilter.insert(properties, comparator); | ||
135 | } | 152 | } |
136 | 153 | ||
137 | void setType(const QByteArray &type) | 154 | void setType(const QByteArray &type) |
@@ -373,6 +390,13 @@ public: | |||
373 | return *this; | 390 | return *this; |
374 | } | 391 | } |
375 | 392 | ||
393 | template <typename T1, typename T2, typename... Rest> | ||
394 | Query &filter(const QueryBase::Comparator &comparator) | ||
395 | { | ||
396 | QueryBase::filter({T1::name, T2::name, Rest::name...}, comparator); | ||
397 | return *this; | ||
398 | } | ||
399 | |||
376 | Query &filter(const QByteArray &id) | 400 | Query &filter(const QByteArray &id) |
377 | { | 401 | { |
378 | QueryBase::filter(id); | 402 | QueryBase::filter(id); |
@@ -465,13 +489,13 @@ public: | |||
465 | template <typename T> | 489 | template <typename T> |
466 | Query &resourceFilter(const ApplicationDomain::ApplicationDomainType &entity) | 490 | Query &resourceFilter(const ApplicationDomain::ApplicationDomainType &entity) |
467 | { | 491 | { |
468 | mResourceFilter.propertyFilter.insert(T::name, Comparator(entity.identifier())); | 492 | mResourceFilter.propertyFilter.insert({T::name}, Comparator(entity.identifier())); |
469 | return *this; | 493 | return *this; |
470 | } | 494 | } |
471 | 495 | ||
472 | Query &resourceFilter(const QByteArray &name, const Comparator &comparator) | 496 | Query &resourceFilter(const QByteArray &name, const Comparator &comparator) |
473 | { | 497 | { |
474 | mResourceFilter.propertyFilter.insert(name, comparator); | 498 | mResourceFilter.propertyFilter.insert({name}, comparator); |
475 | return *this; | 499 | return *this; |
476 | } | 500 | } |
477 | 501 | ||
@@ -531,13 +555,13 @@ public: | |||
531 | template <typename T> | 555 | template <typename T> |
532 | SyncScope &resourceFilter(const ApplicationDomain::ApplicationDomainType &entity) | 556 | SyncScope &resourceFilter(const ApplicationDomain::ApplicationDomainType &entity) |
533 | { | 557 | { |
534 | mResourceFilter.propertyFilter.insert(T::name, Comparator(entity.identifier())); | 558 | mResourceFilter.propertyFilter.insert({T::name}, Comparator(entity.identifier())); |
535 | return *this; | 559 | return *this; |
536 | } | 560 | } |
537 | 561 | ||
538 | SyncScope &resourceFilter(const QByteArray &name, const Comparator &comparator) | 562 | SyncScope &resourceFilter(const QByteArray &name, const Comparator &comparator) |
539 | { | 563 | { |
540 | mResourceFilter.propertyFilter.insert(name, comparator); | 564 | mResourceFilter.propertyFilter.insert({name}, comparator); |
541 | return *this; | 565 | return *this; |
542 | } | 566 | } |
543 | 567 | ||