summary refs log tree commit diff stats
path: root/lib/statement.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-06 20:58:37 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-06 20:58:37 -0500
commitf1f67e62cebb4144f0599196263cd93b41fa972e (patch)
tree5d0f8fceeec63f47fb85846f5568bcb36f4a975f /lib/statement.h
parent6cc23ba387d0813b801ba094709673a61bac889c (diff)
downloadverbly-f1f67e62cebb4144f0599196263cd93b41fa972e.tar.gz
verbly-f1f67e62cebb4144f0599196263cd93b41fa972e.tar.bz2
verbly-f1f67e62cebb4144f0599196263cd93b41fa972e.zip
Made pronunciation::rhymes join dynamic
This involved adding a new type of filter; one that compares (currently
only equality and inequality) a field with another field located in an
enclosing join context.

In the process, it was discovered that simplifying the lemma::forms join
field earlier actually made some queries return inaccurate results
because the inflection of the form was being ignored and anything in the
lemma would be used because of the inner join. Because the existing
condition join did not allow for the condition field to be on the from
side of the join, two things were done: a condition version of
joinThrough was made, and lemma was finally eliminated as a top-level
object, replaced instead with a condition join between word and form
through lemmas_forms.

Queries are also now grouped by the first select field (assumed to be
the primary ID) of the top table, in order to eliminate duplicates
created by inner joins, so that there is a uniform distribution between
results for random queries.

Created a database index on pronunciations(rhyme) which decreases query
time for rhyming filters. The new database version is
backwards-compatible because no data or structure changed.
Diffstat (limited to 'lib/statement.h')
-rw-r--r--lib/statement.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/statement.h b/lib/statement.h index 15c4ac3..2fadf05 100644 --- a/lib/statement.h +++ b/lib/statement.h
@@ -140,7 +140,7 @@ namespace verbly {
140 140
141 condition(std::string table, std::string column, bool isNull); 141 condition(std::string table, std::string column, bool isNull);
142 142
143 condition(std::string table, std::string column, comparison comp, binding value); 143 condition(std::string table, std::string column, comparison comp, binding value, object parentObject = object::undefined);
144 144
145 // Group 145 // Group
146 146
@@ -160,6 +160,8 @@ namespace verbly {
160 160
161 condition flatten() const; 161 condition flatten() const;
162 162
163 condition resolveCompareFields(object context, std::string tableName) const;
164
163 private: 165 private:
164 union { 166 union {
165 struct { 167 struct {
@@ -167,6 +169,7 @@ namespace verbly {
167 std::string column_; 169 std::string column_;
168 comparison comparison_; 170 comparison comparison_;
169 binding value_; 171 binding value_;
172 object parentObject_;
170 } singleton_; 173 } singleton_;
171 struct { 174 struct {
172 std::list<condition> children_; 175 std::list<condition> children_;
@@ -251,7 +254,6 @@ namespace verbly {
251 : (context == object::word) ? "words" 254 : (context == object::word) ? "words"
252 : (context == object::frame) ? "frames" 255 : (context == object::frame) ? "frames"
253 : (context == object::part) ? "parts" 256 : (context == object::part) ? "parts"
254 : (context == object::lemma) ? "lemmas_forms"
255 : (context == object::form) ? "forms" 257 : (context == object::form) ? "forms"
256 : (context == object::pronunciation) ? "pronunciations" 258 : (context == object::pronunciation) ? "pronunciations"
257 : throw std::domain_error("Provided context has no associated table"); 259 : throw std::domain_error("Provided context has no associated table");
@@ -259,7 +261,7 @@ namespace verbly {
259 261
260 static const std::list<field> getSelectForContext(object context); 262 static const std::list<field> getSelectForContext(object context);
261 263
262 statement(std::string tableName, filter clause, int nextTableId = 0, int nextWithId = 0); 264 statement(object context, std::string tableName, filter clause, int nextTableId = 0, int nextWithId = 0);
263 265
264 condition parseFilter(filter queryFilter); 266 condition parseFilter(filter queryFilter);
265 267
@@ -272,6 +274,7 @@ namespace verbly {
272 int nextTableId_; 274 int nextTableId_;
273 int nextWithId_; 275 int nextWithId_;
274 276
277 object context_;
275 std::map<std::string, std::string> tables_; 278 std::map<std::string, std::string> tables_;
276 std::string topTable_; 279 std::string topTable_;
277 std::list<join> joins_; 280 std::list<join> joins_;