From f1f67e62cebb4144f0599196263cd93b41fa972e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 6 Feb 2017 20:58:37 -0500 Subject: 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. --- lib/statement.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/statement.h') 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 { condition(std::string table, std::string column, bool isNull); - condition(std::string table, std::string column, comparison comp, binding value); + condition(std::string table, std::string column, comparison comp, binding value, object parentObject = object::undefined); // Group @@ -160,6 +160,8 @@ namespace verbly { condition flatten() const; + condition resolveCompareFields(object context, std::string tableName) const; + private: union { struct { @@ -167,6 +169,7 @@ namespace verbly { std::string column_; comparison comparison_; binding value_; + object parentObject_; } singleton_; struct { std::list children_; @@ -251,7 +254,6 @@ namespace verbly { : (context == object::word) ? "words" : (context == object::frame) ? "frames" : (context == object::part) ? "parts" - : (context == object::lemma) ? "lemmas_forms" : (context == object::form) ? "forms" : (context == object::pronunciation) ? "pronunciations" : throw std::domain_error("Provided context has no associated table"); @@ -259,7 +261,7 @@ namespace verbly { static const std::list getSelectForContext(object context); - statement(std::string tableName, filter clause, int nextTableId = 0, int nextWithId = 0); + statement(object context, std::string tableName, filter clause, int nextTableId = 0, int nextWithId = 0); condition parseFilter(filter queryFilter); @@ -272,6 +274,7 @@ namespace verbly { int nextTableId_; int nextWithId_; + object context_; std::map tables_; std::string topTable_; std::list joins_; -- cgit 1.4.1