Mercurial > hg > orthanc
comparison OrthancServer/Search/LookupIdentifierQuery.h @ 2697:e583478e0c6c jobs
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 03 Jul 2018 15:59:17 +0200 |
parents | 1b736d151ea1 |
children | 7695a9c81099 |
comparison
equal
deleted
inserted
replaced
2696:1b736d151ea1 | 2697:e583478e0c6c |
---|---|
63 * method "NormalizeIdentifier()". | 63 * method "NormalizeIdentifier()". |
64 **/ | 64 **/ |
65 | 65 |
66 class LookupIdentifierQuery : public boost::noncopyable | 66 class LookupIdentifierQuery : public boost::noncopyable |
67 { | 67 { |
68 // This class encodes a conjunction ("AND") of disjunctions. Each | |
69 // disjunction represents an "OR" of several constraints. | |
70 | |
68 public: | 71 public: |
69 class Constraint | 72 class SingleConstraint |
70 { | 73 { |
71 private: | 74 private: |
72 DicomTag tag_; | 75 DicomTag tag_; |
73 IdentifierConstraintType type_; | 76 IdentifierConstraintType type_; |
74 std::string value_; | 77 std::string value_; |
75 | 78 |
76 public: | 79 public: |
77 Constraint(const DicomTag& tag, | 80 SingleConstraint(const DicomTag& tag, |
78 IdentifierConstraintType type, | 81 IdentifierConstraintType type, |
79 const std::string& value) : | 82 const std::string& value) : |
80 tag_(tag), | 83 tag_(tag), |
81 type_(type), | 84 type_(type), |
82 value_(ServerToolbox::NormalizeIdentifier(value)) | 85 value_(ServerToolbox::NormalizeIdentifier(value)) |
83 { | 86 { |
84 } | 87 } |
98 return value_; | 101 return value_; |
99 } | 102 } |
100 }; | 103 }; |
101 | 104 |
102 | 105 |
106 class RangeConstraint | |
107 { | |
108 private: | |
109 DicomTag tag_; | |
110 std::string start_; | |
111 std::string end_; | |
112 | |
113 public: | |
114 RangeConstraint(const DicomTag& tag, | |
115 const std::string& start, | |
116 const std::string& end) : | |
117 tag_(tag), | |
118 start_(ServerToolbox::NormalizeIdentifier(start)), | |
119 end_(ServerToolbox::NormalizeIdentifier(end)) | |
120 { | |
121 } | |
122 | |
123 const DicomTag& GetTag() const | |
124 { | |
125 return tag_; | |
126 } | |
127 | |
128 const std::string& GetStart() const | |
129 { | |
130 return start_; | |
131 } | |
132 | |
133 const std::string& GetEnd() const | |
134 { | |
135 return end_; | |
136 } | |
137 }; | |
138 | |
139 | |
103 class Disjunction : public boost::noncopyable | 140 class Disjunction : public boost::noncopyable |
104 { | 141 { |
105 private: | 142 private: |
106 std::vector<Constraint*> constraints_; | 143 std::vector<SingleConstraint*> singleConstraints_; |
144 std::vector<RangeConstraint*> rangeConstraints_; | |
107 | 145 |
108 public: | 146 public: |
109 ~Disjunction(); | 147 ~Disjunction(); |
110 | 148 |
111 void Add(const DicomTag& tag, | 149 void Add(const DicomTag& tag, |
112 IdentifierConstraintType type, | 150 IdentifierConstraintType type, |
113 const std::string& value); | 151 const std::string& value); |
114 | 152 |
115 size_t GetSize() const | 153 void AddRange(const DicomTag& tag, |
116 { | 154 const std::string& start, |
117 return constraints_.size(); | 155 const std::string& end); |
118 } | 156 |
119 | 157 size_t GetSingleConstraintsCount() const |
120 const Constraint& GetConstraint(size_t i) const | 158 { |
121 { | 159 return singleConstraints_.size(); |
122 return *constraints_[i]; | 160 } |
161 | |
162 const SingleConstraint& GetSingleConstraint(size_t i) const | |
163 { | |
164 return *singleConstraints_[i]; | |
165 } | |
166 | |
167 size_t GetRangeConstraintsCount() const | |
168 { | |
169 return rangeConstraints_.size(); | |
170 } | |
171 | |
172 const RangeConstraint& GetRangeConstraint(size_t i) const | |
173 { | |
174 return *rangeConstraints_[i]; | |
123 } | 175 } |
124 }; | 176 }; |
125 | 177 |
126 | 178 |
127 private: | 179 private: |
128 typedef std::vector<Disjunction*> Disjuntions; | 180 typedef std::vector<Disjunction*> Disjunctions; |
129 | 181 |
130 ResourceType level_; | 182 ResourceType level_; |
131 Disjuntions disjuntions_; | 183 Disjunctions disjunctions_; |
132 | 184 |
133 public: | 185 public: |
134 LookupIdentifierQuery(ResourceType level) : level_(level) | 186 LookupIdentifierQuery(ResourceType level) : level_(level) |
135 { | 187 { |
136 } | 188 } |
144 | 196 |
145 void AddConstraint(DicomTag tag, | 197 void AddConstraint(DicomTag tag, |
146 IdentifierConstraintType type, | 198 IdentifierConstraintType type, |
147 const std::string& value); | 199 const std::string& value); |
148 | 200 |
201 void AddRange(DicomTag tag, | |
202 const std::string& start, | |
203 const std::string& end); | |
204 | |
149 Disjunction& AddDisjunction(); | 205 Disjunction& AddDisjunction(); |
150 | 206 |
151 ResourceType GetLevel() const | 207 ResourceType GetLevel() const |
152 { | 208 { |
153 return level_; | 209 return level_; |
154 } | |
155 | |
156 size_t GetSize() const | |
157 { | |
158 return disjuntions_.size(); | |
159 } | 210 } |
160 | 211 |
161 // The database must be locked | 212 // The database must be locked |
162 void Apply(std::list<std::string>& result, | 213 void Apply(std::list<std::string>& result, |
163 IDatabaseWrapper& database); | 214 IDatabaseWrapper& database); |