r25779 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25778‎ | r25779 | r25780 >
Date:15:14, 11 September 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Enabled sorting queries for properties of types other than Type:Page.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -1518,10 +1518,10 @@
15191519 * be computed).
15201520 *
15211521 * Some notes on sorting: sorting is applied only to fields that appear in the query
1522 - * by verifying conditions and the sorting conditions thus operate on the values that
1523 - * satisfy the given conditions. This may have side effects in cases where one porperty
 1522+ * by verifying conditions, and the sorting conditions thus operate on the values that
 1523+ * satisfy the given conditions. This may have side effects in cases where one property
15241524 * that shall be sorted has multiple values. If no condition other than existence applies
1525 - * to such a property, the value that is relevant for sorting is not really dertermined and
 1525+ * to such a property, the value that is relevant for sorting is not really determined and
15261526 * the behaviour of SQL is not clear (I think). If the condition preselects larger or smaller
15271527 * values, however, then these would probably be used for sorting. Overall this should not
15281528 * be a problem, since it only occurs in cases where the sort order is not fully specified anyway.
@@ -1534,11 +1534,10 @@
15351535 * @param $db The database object
15361536 * @param $curtables Array with names of aliases of tables refering to the 'current' element (the one to which the description basically applies).
15371537 * @param $nary_pos If the subcondition is directly appended to an nary relation, this parameter holds the numerical index of the position in the nary in order to be able to join condition tables to that position.
1538 - * @param $sort True if the subcondition should be used for sorting. This is only meaningful for queries that are below some property statement.
15391538 *
15401539 * @TODO: Maybe there need to be optimisations in certain cases (atomic implementation for common nestings of descriptions?)
15411540 */
1542 - protected function createSQLQuery(SMWDescription $description, &$from, &$where, &$db, &$curtables, $nary_pos = '', $sort = false) {
 1541+ protected function createSQLQuery(SMWDescription $description, &$from, &$where, &$db, &$curtables, $nary_pos = '') {
15431542 $subwhere = '';
15441543 if ($description instanceof SMWThingDescription) {
15451544 // nothing to check
@@ -1661,11 +1660,15 @@
16621661 }
16631662 } elseif ($description instanceof SMWSomeProperty) {
16641663 $id = SMWDataValueFactory::getPropertyObjectTypeID($description->getProperty());
 1664+ $sort = false;
16651665 switch ($id) {
16661666 case '_wpg':
16671667 $tablename = 'RELS';
16681668 $pcolumn = 'relation_title';
16691669 $sub = true;
 1670+ if ($this->m_sortkey == $description->getProperty()->getDBKey()) {
 1671+ $sort = 'object_title';
 1672+ }
16701673 break;
16711674 case '_txt':
16721675 $tablename = 'TEXT';
@@ -1681,6 +1684,13 @@
16821685 $tablename = 'ATTS';
16831686 $pcolumn = 'attribute_title';
16841687 $sub = true;
 1688+ if ($this->m_sortkey == $description->getProperty()->getDBKey()) {
 1689+ if (SMWDataValueFactory::newTypeIDValue($id)->isNumeric()) {
 1690+ $sort = 'value_num';
 1691+ } else {
 1692+ $sort = 'value_xsd';
 1693+ }
 1694+ }
16851695 }
16861696 if ($table = $this->addJoin($tablename, $from, $db, $curtables, $nary_pos)) {
16871697 global $smwgQSubpropertyDepth;
@@ -1695,7 +1705,10 @@
16961706 if ($sub) {
16971707 $nexttables = array();
16981708 $nexttables['p' . $tablename] = $table; // keep only current table for reference
1699 - $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $nexttables, $nary_pos, ($this->m_sortkey == $description->getProperty()->getDBKey()) );
 1709+ $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $nexttables, $nary_pos);
 1710+ if ($sort) {
 1711+ $this->m_sortfield = "$table.$sort";
 1712+ }
17001713 if ( $subwhere != '') {
17011714 $where .= ' AND (' . $subwhere . ')';
17021715 }
@@ -1703,11 +1716,6 @@
17041717 }
17051718 }
17061719
1707 - if ($sort && (!$description instanceof SMWValueDescription) ) {
1708 - if (array_key_exists('pRELS', $curtables)) {
1709 - $this->m_sortfield = $curtables['pRELS'] . '.object_title';
1710 - }
1711 - }
17121720 }
17131721
17141722 /**

Status & tagging log