Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php |
— | — | @@ -10,47 +10,59 @@ |
11 | 11 | require_once('DefinedMeaningModel.php'); |
12 | 12 | require_once('ViewInformation.php'); |
13 | 13 | |
| 14 | + |
14 | 15 | function getSynonymSQLForLanguage($languageId, array &$definedMeaningIds) { |
15 | 16 | $dc=wdGetDataSetContext(); |
16 | | - |
17 | | - return |
18 | | - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
| 17 | + |
| 18 | + # Query building |
| 19 | + $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
19 | 20 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
20 | | - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" . |
21 | | - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") . |
| 21 | + " WHERE " . getLatestTransactionRestriction("{$dc}_syntrans") . |
22 | 22 | " AND " . getLatestTransactionRestriction("{$dc}_expression") . |
23 | 23 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") . |
24 | 24 | " AND {$dc}_expression.language_id=" . $languageId . |
25 | 25 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
26 | 26 | " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " . |
27 | 27 | " AND {$dc}_syntrans.identical_meaning=1 " . |
28 | | - " GROUP BY {$dc}_defined_meaning.defined_meaning_id"; |
| 28 | + " AND {$dc}_defined_meaning.defined_meaning_id = "; |
| 29 | + |
| 30 | + # Build atomic queries |
| 31 | + $definedMeaningIdsCopy = $definedMeaningIds; |
| 32 | + foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; } |
| 33 | + unset($value); |
| 34 | + # Union of the atoms |
| 35 | + return implode(' UNION ',$definedMeaningIdsCopy); |
29 | 36 | } |
30 | 37 | |
31 | 38 | function getSynonymSQLForAnyLanguage(array &$definedMeaningIds) { |
32 | 39 | $dc=wdGetDataSetContext(); |
33 | 40 | |
34 | | - return |
35 | | - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
| 41 | + # Query building |
| 42 | + $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
36 | 43 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
37 | | - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" . |
38 | | - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") . |
| 44 | + " WHERE " . getLatestTransactionRestriction("{$dc}_syntrans") . |
39 | 45 | " AND " . getLatestTransactionRestriction("{$dc}_expression") . |
40 | 46 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") . |
41 | 47 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
42 | 48 | " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " . |
43 | 49 | " AND {$dc}_syntrans.identical_meaning=1 " . |
44 | | - " GROUP BY {$dc}_defined_meaning.defined_meaning_id"; |
| 50 | + " AND {$dc}_defined_meaning.defined_meaning_id = "; |
| 51 | + |
| 52 | + # Build atomic queries |
| 53 | + $definedMeaningIdsCopy = $definedMeaningIds; |
| 54 | + foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; } |
| 55 | + unset($value); |
| 56 | + # Union of the atoms |
| 57 | + return implode(' UNION ',$definedMeaningIdsCopy); |
45 | 58 | } |
46 | 59 | |
47 | 60 | function getDefiningSQLForLanguage($languageId, array &$definedMeaningIds) { |
48 | 61 | $dc=wdGetDataSetContext(); |
49 | 62 | |
50 | | - return |
51 | | - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
| 63 | + # Query building |
| 64 | + $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
52 | 65 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
53 | | - " WHERE {$dc}_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" . |
54 | | - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") . |
| 66 | + " WHERE ". getLatestTransactionRestriction("{$dc}_syntrans") . |
55 | 67 | " AND " . getLatestTransactionRestriction("{$dc}_expression") . |
56 | 68 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") . |
57 | 69 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
— | — | @@ -58,9 +70,17 @@ |
59 | 71 | " AND {$dc}_syntrans.identical_meaning=1 " . |
60 | 72 | " AND {$dc}_defined_meaning.expression_id={$dc}_expression.expression_id " . |
61 | 73 | " AND {$dc}_expression.language_id=" . $languageId . |
62 | | - " GROUP BY {$dc}_defined_meaning.defined_meaning_id"; |
| 74 | + " AND {$dc}_defined_meaning.defined_meaning_id = "; |
| 75 | + |
| 76 | + # Build atomic queries |
| 77 | + $definedMeaningIdsCopy = $definedMeaningIds; |
| 78 | + foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; } |
| 79 | + unset($value); |
| 80 | + # Union of the atoms |
| 81 | + return implode(' UNION ',$definedMeaningIdsCopy); |
63 | 82 | } |
64 | 83 | |
| 84 | + |
65 | 85 | function fetchDefinedMeaningReferenceRecords($sql, array &$definedMeaningIds, array &$definedMeaningReferenceRecords, $usedAs='defined-meaning') { |
66 | 86 | $dc=wdGetDataSetContext(); |
67 | 87 | |
— | — | @@ -88,22 +108,32 @@ |
89 | 109 | $definedMeaningIds = array_diff($definedMeaningIds, $foundDefinedMeaningIds); |
90 | 110 | } |
91 | 111 | |
| 112 | + |
92 | 113 | function fetchDefinedMeaningDefiningExpressions(array &$definedMeaningIds, array &$definedMeaningReferenceRecords) { |
93 | | - |
94 | 114 | $o=OmegaWikiAttributes::getInstance(); |
95 | 115 | |
96 | 116 | $dc=wdGetDataSetContext(); |
97 | 117 | |
98 | 118 | $dbr =& wfGetDB(DB_SLAVE); |
99 | | - $queryResult = $dbr->query( |
100 | | - "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" . |
| 119 | + |
| 120 | + # Query building |
| 121 | + $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" . |
101 | 122 | " FROM {$dc}_defined_meaning, {$dc}_expression " . |
102 | 123 | " WHERE {$dc}_defined_meaning.expression_id={$dc}_expression.expression_id " . |
103 | 124 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning") . |
104 | 125 | " AND " . getLatestTransactionRestriction("{$dc}_expression") . |
105 | | - " AND {$dc}_defined_meaning.defined_meaning_id IN (". implode(", ", $definedMeaningIds) .")" |
106 | | - ); |
| 126 | + " AND {$dc}_defined_meaning.defined_meaning_id = "; |
107 | 127 | |
| 128 | + # Build atomic queries |
| 129 | + $definedMeaningIdsCopy = $definedMeaningIds; |
| 130 | + unset($value); |
| 131 | + foreach ($definedMeaningIdsCopy as &$value) {$value = $frontQuery . $value; } |
| 132 | + unset($value); |
| 133 | + # Union of the atoms |
| 134 | + $finalQuery = implode(' UNION ',$definedMeaningIdsCopy); |
| 135 | + |
| 136 | + $queryResult = $dbr->query($finalQuery); |
| 137 | + |
108 | 138 | while ($row = $dbr->fetchObject($queryResult)) { |
109 | 139 | $definedMeaningReferenceRecord = $definedMeaningReferenceRecords[$row->defined_meaning_id]; |
110 | 140 | |
— | — | @@ -115,7 +145,7 @@ |
116 | 146 | } |
117 | 147 | |
118 | 148 | $definedMeaningReferenceRecord->definedMeaningDefiningExpression = $row->spelling; |
119 | | - } |
| 149 | + } |
120 | 150 | } |
121 | 151 | |
122 | 152 | function getNullDefinedMeaningReferenceRecord() { |
— | — | @@ -227,18 +257,25 @@ |
228 | 258 | function getExpressionReferenceRecords($expressionIds) { |
229 | 259 | |
230 | 260 | $o=OmegaWikiAttributes::getInstance(); |
231 | | - |
232 | 261 | $dc=wdGetDataSetContext(); |
233 | 262 | |
234 | 263 | if (count($expressionIds) > 0) { |
235 | 264 | $dbr =& wfGetDB(DB_SLAVE); |
236 | | - $queryResult = $dbr->query( |
237 | | - "SELECT expression_id, language_id, spelling" . |
| 265 | + |
| 266 | + # Query building |
| 267 | + $frontQuery = "SELECT expression_id, language_id, spelling" . |
238 | 268 | " FROM {$dc}_expression" . |
239 | | - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" . |
240 | | - " AND ". getLatestTransactionRestriction("{$dc}_expression") |
241 | | - ); |
| 269 | + " WHERE expression_id = "; |
| 270 | + $queueQuery = " AND ". getLatestTransactionRestriction("{$dc}_expression"); |
| 271 | + |
| 272 | + # Build atomic queries |
| 273 | + foreach ($expressionIds as &$value) {$value = $frontQuery . $value . $queueQuery; } |
| 274 | + unset($value); |
| 275 | + # Union of the atoms |
| 276 | + $finalQuery = implode(' UNION ',$expressionIds); |
242 | 277 | |
| 278 | + $queryResult = $dbr->query($finalQuery); |
| 279 | + |
243 | 280 | $result = array(); |
244 | 281 | |
245 | 282 | while ($row = $dbr->fetchObject($queryResult)) { |
— | — | @@ -270,20 +307,22 @@ |
271 | 308 | } |
272 | 309 | |
273 | 310 | function getExpressionSpellings(array $expressionIds) { |
274 | | - |
275 | | - $o=OmegaWikiAttributes::getInstance(); |
276 | | - |
277 | 311 | $dc=wdGetDataSetContext(); |
278 | 312 | |
279 | 313 | if (count($expressionIds) > 0) { |
280 | 314 | $dbr =& wfGetDB(DB_SLAVE); |
281 | | - $queryResult = $dbr->query( |
282 | | - "SELECT expression_id, spelling" . |
283 | | - " FROM {$dc}_expression" . |
284 | | - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" . |
285 | | - " AND ". getLatestTransactionRestriction("{$dc}_expression") |
286 | | - ); |
287 | 315 | |
| 316 | + # Prepare steady components |
| 317 | + $frontQuery = "SELECT expression_id, spelling FROM {$dc}_expression WHERE expression_id ="; |
| 318 | + $queueQuery = " AND ". getLatestTransactionRestriction("{$dc}_expression"); |
| 319 | + # Build atomic queries |
| 320 | + foreach ($expressionIds as &$value) {$value = $frontQuery . $value . $queueQuery; } |
| 321 | + unset($value); |
| 322 | + # Union of the atoms |
| 323 | + $finalQuery = implode(' UNION ',$expressionIds); |
| 324 | + |
| 325 | + $queryResult = $dbr->query($finalQuery); |
| 326 | + |
288 | 327 | $result = array(); |
289 | 328 | |
290 | 329 | while ($row = $dbr->fetchObject($queryResult)) |
— | — | @@ -313,12 +352,20 @@ |
314 | 353 | $dc=wdGetDataSetContext(); |
315 | 354 | if (count($textIds) > 0) { |
316 | 355 | $dbr =& wfGetDB(DB_SLAVE); |
317 | | - $queryResult = $dbr->query( |
318 | | - "SELECT text_id, text_text" . |
| 356 | + |
| 357 | + # Query building |
| 358 | + $frontQuery = "SELECT text_id, text_text" . |
319 | 359 | " FROM {$dc}_text" . |
320 | | - " WHERE text_id IN (". implode(', ', $textIds) .")" |
321 | | - ); |
| 360 | + " WHERE text_id = "; |
| 361 | + |
| 362 | + # Build atomic queries |
| 363 | + foreach ($textIds as &$value) {$value = $frontQuery . $value; } |
| 364 | + unset($value); |
| 365 | + # Union of the atoms |
| 366 | + $finalQuery = implode(' UNION ',$textIds); |
322 | 367 | |
| 368 | + $queryResult = $dbr->query($finalQuery); |
| 369 | + |
323 | 370 | $result = array(); |
324 | 371 | |
325 | 372 | while ($row = $dbr->fetchObject($queryResult)) |