Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -7,8 +7,7 @@ |
8 | 8 | |
9 | 9 | global $smwgIP; |
10 | 10 | require_once( "$smwgIP/includes/storage/SMW_Store.php" ); |
11 | | -require_once( "$smwgIP/includes/SMW_Datatype.php" ); |
12 | | -require_once( "$smwgIP/includes/SMW_DataValue.php" ); |
| 11 | +require_once( "$smwgIP/includes/SMW_DataValueFactory.php" ); |
13 | 12 | |
14 | 13 | /** |
15 | 14 | * Storage access class for using the standard MediaWiki SQL database |
— | — | @@ -34,10 +33,19 @@ |
35 | 34 | */ |
36 | 35 | static protected $m_tablenum = 0; |
37 | 36 | /** |
38 | | - * Array of names of virtual tables that hold the upper closure of certain |
| 37 | + * Array of names of virtual tables that hold the lower closure of certain |
39 | 38 | * categories wrt. hierarchy. |
40 | 39 | */ |
41 | 40 | static protected $m_categorytables = array(); |
| 41 | + /** |
| 42 | + * Array of names of virtual tables that hold the lower closure of certain |
| 43 | + * categories wrt. hierarchy. |
| 44 | + */ |
| 45 | + static protected $m_propertytables = array(); |
| 46 | + /** |
| 47 | + * Record all virtual tables used for a single operation (especially query) to produce debug output. |
| 48 | + */ |
| 49 | + protected $m_usedtables; |
42 | 50 | |
43 | 51 | |
44 | 52 | ///// Reading methods ///// |
— | — | @@ -618,6 +626,7 @@ |
619 | 627 | $prs = $query->getDescription()->getPrintrequests(); // ignore print requests at deeper levels |
620 | 628 | |
621 | 629 | // Build main query |
| 630 | + $this->m_usedtables = array(); |
622 | 631 | $this->m_sortkey = $query->sortkey; |
623 | 632 | $this->m_sortfield = false; |
624 | 633 | |
— | — | @@ -668,12 +677,12 @@ |
669 | 678 | foreach ($query->getErrors() as $error) { |
670 | 679 | $result .= $error . '<br />'; |
671 | 680 | } |
672 | | - $result .= '<br /><b>Auxilliary tables used (possibly in multiple copies)</b><br />'; |
673 | | - foreach (SMWSQLStore::$m_categorytables as $tablename) { |
| 681 | + $result .= '<br /><b>Auxilliary tables used</b><br />'; |
| 682 | + foreach ($this->m_usedtables as $tablename) { |
674 | 683 | $result .= $tablename . ': '; |
675 | | - $res = $db->query( "SELECT cat_name FROM $tablename", 'SMW::getQueryResult:DEBUG'); |
| 684 | + $res = $db->query( "SELECT title FROM $tablename", 'SMW::getQueryResult:DEBUG'); |
676 | 685 | while ( $row = $db->fetchObject($res) ) { |
677 | | - $result .= $row->cat_name . ', '; |
| 686 | + $result .= $row->title . ', '; |
678 | 687 | } |
679 | 688 | $result .= '<br />'; |
680 | 689 | } |
— | — | @@ -880,50 +889,51 @@ |
881 | 890 | } |
882 | 891 | |
883 | 892 | /** |
884 | | - * Make a (temporary) table that contains the upper closure of the given category |
| 893 | + * Make a (temporary) table that contains the lower closure of the given category |
885 | 894 | * wrt. the category table. |
886 | 895 | */ |
887 | 896 | protected function getCategoryTable($catname, &$db) { |
888 | | - global $wgDBname, $smwgIQSubcategoryInclusions; |
| 897 | + global $wgDBname, $smwgQSubcategoryDepth; |
889 | 898 | |
890 | 899 | $tablename = 'cats' . SMWSQLStore::$m_tablenum++; |
| 900 | + $this->m_usedtables[] = $tablename; |
891 | 901 | $db->query( 'CREATE TEMPORARY TABLE ' . $tablename . |
892 | | - '( cat_name VARCHAR(255) NOT NULL ) |
| 902 | + '( title VARCHAR(255) NOT NULL ) |
893 | 903 | TYPE=MEMORY', 'SMW::getCategoryTable' ); |
894 | 904 | if (array_key_exists($catname, SMWSQLStore::$m_categorytables)) { // just copy known result |
895 | | - $db->query("INSERT INTO $tablename (cat_name) SELECT " . |
| 905 | + $db->query("INSERT INTO $tablename (title) SELECT " . |
896 | 906 | SMWSQLStore::$m_categorytables[$catname] . |
897 | | - '.cat_name FROM ' . SMWSQLStore::$m_categorytables[$catname], |
| 907 | + '.title FROM ' . SMWSQLStore::$m_categorytables[$catname], |
898 | 908 | 'SMW::getCategoryTable'); |
899 | 909 | return $tablename; |
900 | 910 | } |
901 | 911 | |
902 | 912 | // Create multiple temporary tables for recursive computation |
903 | 913 | $db->query( 'CREATE TEMPORARY TABLE smw_newcats |
904 | | - ( cat_name VARCHAR(255) NOT NULL ) |
| 914 | + ( title VARCHAR(255) NOT NULL ) |
905 | 915 | TYPE=MEMORY', 'SMW::getCategoryTable' ); |
906 | 916 | $db->query( 'CREATE TEMPORARY TABLE smw_rescats |
907 | | - ( cat_name VARCHAR(255) NOT NULL ) |
| 917 | + ( title VARCHAR(255) NOT NULL ) |
908 | 918 | TYPE=MEMORY', 'SMW::getCategoryTable' ); |
909 | 919 | $tmpnew = 'smw_newcats'; |
910 | 920 | $tmpres = 'smw_rescats'; |
911 | 921 | |
912 | 922 | $pagetable = $db->tableName('page'); |
913 | 923 | $cltable = $db->tableName('categorylinks'); |
914 | | - $db->query("INSERT INTO $tablename (cat_name) VALUES ('$catname')", 'SMW::getCategoryTable'); |
915 | | - $db->query("INSERT INTO smw_newcats (cat_name) VALUES ('$catname')", 'SMW::getCategoryTable'); |
| 924 | + $db->query("INSERT INTO $tablename (title) VALUES ('$catname')", 'SMW::getCategoryTable'); |
| 925 | + $db->query("INSERT INTO $tmpnew (title) VALUES ('$catname')", 'SMW::getCategoryTable'); |
916 | 926 | |
917 | 927 | /// TODO: avoid duplicate results? |
918 | | - for ($i=0; $i<$smwgIQSubcategoryInclusions; $i++) { |
919 | | - $db->query("INSERT INTO $tmpres (cat_name) SELECT $pagetable.page_title |
| 928 | + for ($i=0; $i<$smwgQSubcategoryDepth; $i++) { |
| 929 | + $db->query("INSERT INTO $tmpres (title) SELECT $pagetable.page_title |
920 | 930 | FROM $cltable,$pagetable,$tmpnew WHERE |
921 | | - $cltable.cl_to=$tmpnew.cat_name AND |
| 931 | + $cltable.cl_to=$tmpnew.title AND |
922 | 932 | $pagetable.page_namespace=" . NS_CATEGORY . " AND |
923 | 933 | $pagetable.page_id=$cltable.cl_from", 'SMW::getCategoryTable'); |
924 | 934 | if ($db->affectedRows() == 0) { // no change, exit loop |
925 | 935 | continue; |
926 | 936 | } |
927 | | - $db->query("INSERT INTO $tablename (cat_name) SELECT $tmpres.cat_name |
| 937 | + $db->query("INSERT INTO $tablename (title) SELECT $tmpres.title |
928 | 938 | FROM $tmpres", 'SMW::getCategoryTable'); |
929 | 939 | $db->query('TRUNCATE TABLE ' . $tmpnew, 'SMW::getCategoryTable'); // empty "new" table |
930 | 940 | $tmpname = $tmpnew; |
— | — | @@ -938,13 +948,68 @@ |
939 | 949 | } |
940 | 950 | |
941 | 951 | /** |
| 952 | + * Make a (temporary) table that contains the lower closure of the given property |
| 953 | + * wrt. the subproperty relation. |
| 954 | + */ |
| 955 | + protected function getPropertyTable($propname, &$db) { |
| 956 | + global $wgDBname, $smwgQSubpropertyDepth; |
| 957 | + |
| 958 | + $tablename = 'prop' . SMWSQLStore::$m_tablenum++; |
| 959 | + $db->query( 'CREATE TEMPORARY TABLE ' . $tablename . |
| 960 | + '( title VARCHAR(255) NOT NULL ) |
| 961 | + TYPE=MEMORY', 'SMW::getPropertyTable' ); |
| 962 | + if (array_key_exists($propname, SMWSQLStore::$m_propertytables)) { // just copy known result |
| 963 | + $db->query("INSERT INTO $tablename (title) SELECT " . |
| 964 | + SMWSQLStore::$m_propertytables[$propname] . |
| 965 | + '.title FROM ' . SMWSQLStore::$m_propertytables[$propname], |
| 966 | + 'SMW::getPropertyTable'); |
| 967 | + return $tablename; |
| 968 | + } |
| 969 | + |
| 970 | + // Create multiple temporary tables for recursive computation |
| 971 | + $db->query( 'CREATE TEMPORARY TABLE smw_new |
| 972 | + ( title VARCHAR(255) NOT NULL ) |
| 973 | + TYPE=MEMORY', 'SMW::getPropertyTable' ); |
| 974 | + $db->query( 'CREATE TEMPORARY TABLE smw_res |
| 975 | + ( title VARCHAR(255) NOT NULL ) |
| 976 | + TYPE=MEMORY', 'SMW::getPropertyTable' ); |
| 977 | + $tmpnew = 'smw_new'; |
| 978 | + $tmpres = 'smw_res'; |
| 979 | + |
| 980 | + $sptable = $db->tableName('smw_subprops'); |
| 981 | + $db->query("INSERT INTO $tablename (title) VALUES ('$propname')", 'SMW::getPropertyTable'); |
| 982 | + $db->query("INSERT INTO $tmpnew (title) VALUES ('$propname')", 'SMW::getPropertyTable'); |
| 983 | + |
| 984 | + /// TODO: avoid duplicate results? |
| 985 | + for ($i=0; $i<$smwgQSubpropertyDepth; $i++) { |
| 986 | + $db->query("INSERT INTO $tmpres (title) SELECT $sptable.subject_title |
| 987 | + FROM $sptable,$tmpnew WHERE |
| 988 | + $sptable.object_title=$tmpnew.title", 'SMW::getPropertyTable'); |
| 989 | + if ($db->affectedRows() == 0) { // no change, exit loop |
| 990 | + continue; |
| 991 | + } |
| 992 | + $db->query("INSERT INTO $tablename (title) SELECT $tmpres.title |
| 993 | + FROM $tmpres", 'SMW::getCategoryTable'); |
| 994 | + $db->query('TRUNCATE TABLE ' . $tmpnew, 'SMW::getPropertyTable'); // empty "new" table |
| 995 | + $tmpname = $tmpnew; |
| 996 | + $tmpnew = $tmpres; |
| 997 | + $tmpres = $tmpname; |
| 998 | + } |
| 999 | + |
| 1000 | + SMWSQLStore::$m_propertytables[$propname] = $tablename; |
| 1001 | + $db->query('DROP TABLE smw_new', 'SMW::getPropertyTable'); |
| 1002 | + $db->query('DROP TABLE smw_res', 'SMW::getPropertyTable'); |
| 1003 | + return $tablename; |
| 1004 | + } |
| 1005 | + |
| 1006 | + /** |
942 | 1007 | * Add the table $tablename to the $from condition via an inner join, |
943 | 1008 | * using the tables that are already available in $curtables (and extending |
944 | 1009 | * $curtables with the new table). Return true if successful or false if it |
945 | 1010 | * wasn't possible to make a suitable inner join. |
946 | 1011 | */ |
947 | | - protected function addInnerJoin($tablename, &$from, &$db, &$curtables) { |
948 | | - global $smwgIQRedirectNormalization; |
| 1012 | + protected function addJoin($tablename, &$from, &$db, &$curtables) { |
| 1013 | + global $smwgQEqualitySupport; |
949 | 1014 | if (array_key_exists($tablename, $curtables)) { // table already present |
950 | 1015 | return true; |
951 | 1016 | } |
— | — | @@ -957,13 +1022,13 @@ |
958 | 1023 | return true; |
959 | 1024 | } |
960 | 1025 | } elseif ($tablename == 'CATS') { |
961 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
| 1026 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
962 | 1027 | $curtables['CATS'] = 'cl' . SMWSQLStore::$m_tablenum++; |
963 | 1028 | $cond = $curtables['CATS'] . '.cl_from=' . $curtables['PAGE'] . '.page_id'; |
964 | 1029 | /// TODO: slow, introduce another parameter to activate this |
965 | | - if ($smwgIQRedirectNormalization && (array_key_exists('PREVREL', $curtables))) { |
| 1030 | + if ($smwgQEqualitySupport && (array_key_exists('PREVREL', $curtables))) { |
966 | 1031 | // only do this at inner queries (PREVREL set) |
967 | | - $this->addInnerJoin('REDIPAGE', $from, $db, $curtables); |
| 1032 | + $this->addJoin('REDIPAGE', $from, $db, $curtables); |
968 | 1033 | $cond = '((' . $cond . ') OR (' . |
969 | 1034 | $curtables['REDIPAGE'] . '.page_id=' . $curtables['CATS'] . '.cl_from))'; |
970 | 1035 | } |
— | — | @@ -971,13 +1036,13 @@ |
972 | 1037 | return true; |
973 | 1038 | } |
974 | 1039 | } elseif ($tablename == 'RELS') { |
975 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
| 1040 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
976 | 1041 | $curtables['RELS'] = 'rel' . SMWSQLStore::$m_tablenum++; |
977 | 1042 | $cond = $curtables['RELS'] . '.subject_id=' . $curtables['PAGE'] . '.page_id'; |
978 | 1043 | /// TODO: slow, introduce another parameter to activate this |
979 | | - if ($smwgIQRedirectNormalization && (array_key_exists('PREVREL', $curtables))) { |
| 1044 | + if ($smwgQEqualitySupport && (array_key_exists('PREVREL', $curtables))) { |
980 | 1045 | // only do this at inner queries (PREVREL set) |
981 | | - $this->addInnerJoin('REDIRECT', $from, $db, $curtables); |
| 1046 | + $this->addJoin('REDIRECT', $from, $db, $curtables); |
982 | 1047 | $cond = '((' . $cond . ') OR (' . |
983 | 1048 | //$curtables['PAGE'] . '.page_id=' . $curtables['REDIRECT'] . '.rd_from AND ' . |
984 | 1049 | $curtables['REDIRECT'] . '.rd_title=' . $curtables['RELS'] . '.subject_title AND ' . |
— | — | @@ -987,13 +1052,13 @@ |
988 | 1053 | return true; |
989 | 1054 | } |
990 | 1055 | } elseif ($tablename == 'ATTS') { |
991 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
| 1056 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
992 | 1057 | $curtables['ATTS'] = 'att' . SMWSQLStore::$m_tablenum++; |
993 | 1058 | $cond = $curtables['ATTS'] . '.subject_id=' . $curtables['PAGE'] . '.page_id'; |
994 | 1059 | /// TODO: slow, introduce another parameter to activate this |
995 | | - if ($smwgIQRedirectNormalization && (array_key_exists('PREVREL', $curtables))) { |
| 1060 | + if ($smwgQEqualitySupport && (array_key_exists('PREVREL', $curtables))) { |
996 | 1061 | // only do this at inner queries (PREVREL set) |
997 | | - $this->addInnerJoin('REDIRECT', $from, $db, $curtables); |
| 1062 | + $this->addJoin('REDIRECT', $from, $db, $curtables); |
998 | 1063 | $cond = '((' . $cond . ') OR (' . |
999 | 1064 | //$curtables['PAGE'] . '.page_id=' . $curtables['REDIRECT'] . '.rd_from AND ' . |
1000 | 1065 | $curtables['REDIRECT'] . '.rd_title=' . $curtables['ATTS'] . '.subject_title AND ' . |
— | — | @@ -1003,19 +1068,19 @@ |
1004 | 1069 | return true; |
1005 | 1070 | } |
1006 | 1071 | } elseif ($tablename == 'TEXT') { |
1007 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
| 1072 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
1008 | 1073 | $curtables['TEXT'] = 'txt' . SMWSQLStore::$m_tablenum++; |
1009 | 1074 | $from .= ' INNER JOIN ' . $db->tableName('smw_longstrings') . ' AS ' . $curtables['TEXT'] . ' ON ' . $curtables['TEXT'] . '.subject_id=' . $curtables['PAGE'] . '.page_id'; |
1010 | 1075 | return true; |
1011 | 1076 | } |
1012 | 1077 | } elseif ($tablename == 'REDIRECT') { |
1013 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
| 1078 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE |
1014 | 1079 | $curtables['REDIRECT'] = 'rd' . SMWSQLStore::$m_tablenum++; |
1015 | 1080 | $from .= ' LEFT JOIN ' . $db->tableName('redirect') . ' AS ' . $curtables['REDIRECT'] . ' ON ' . $curtables['REDIRECT'] . '.rd_from=' . $curtables['PAGE'] . '.page_id'; |
1016 | 1081 | return true; |
1017 | 1082 | } |
1018 | 1083 | } elseif ($tablename == 'REDIPAGE') { // add another copy of page for getting ids of redirect targets |
1019 | | - if ($this->addInnerJoin('REDIRECT', $from, $db, $curtables)) { |
| 1084 | + if ($this->addJoin('REDIRECT', $from, $db, $curtables)) { |
1020 | 1085 | $curtables['REDIPAGE'] = 'rp' . SMWSQLStore::$m_tablenum++; |
1021 | 1086 | $from .= ' INNER JOIN ' . $db->tableName('page') . ' AS ' . $curtables['REDIPAGE'] . ' ON (' . |
1022 | 1087 | $curtables['REDIRECT'] . '.rd_title=' . $curtables['REDIPAGE'] . '.page_title AND ' . |
— | — | @@ -1062,23 +1127,23 @@ |
1063 | 1128 | if ($description instanceof SMWThingDescription) { |
1064 | 1129 | // nothing to check |
1065 | 1130 | } elseif ($description instanceof SMWClassDescription) { |
1066 | | - if ($this->addInnerJoin('CATS', $from, $db, $curtables)) { |
1067 | | - global $smwgIQSubcategoryInclusions; |
1068 | | - if ($smwgIQSubcategoryInclusions > 0) { |
| 1131 | + if ($this->addJoin('CATS', $from, $db, $curtables)) { |
| 1132 | + global $smwgQSubcategoryDepth; |
| 1133 | + if ($smwgQSubcategoryDepth > 0) { |
1069 | 1134 | $ct = $this->getCategoryTable($description->getCategory()->getDBKey(), $db); |
1070 | 1135 | $from = '`' . $ct . '`, ' . $from; |
1071 | | - $where = "$ct.cat_name=" . $curtables['CATS'] . '.cl_to'; |
| 1136 | + $where = "$ct.title=" . $curtables['CATS'] . '.cl_to'; |
1072 | 1137 | } else { |
1073 | 1138 | $where .= $curtables['CATS'] . '.cl_to=' . $db->addQuotes($description->getCategory()->getDBKey()); |
1074 | 1139 | } |
1075 | 1140 | } |
1076 | 1141 | } elseif ($description instanceof SMWNamespaceDescription) { |
1077 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { |
| 1142 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { |
1078 | 1143 | $where .= $curtables['PAGE'] . '.page_namespace=' . $db->addQuotes($description->getNamespace()); |
1079 | 1144 | } |
1080 | 1145 | } elseif ($description instanceof SMWNominalDescription) { |
1081 | | - global $smwgIQRedirectNormalization; |
1082 | | - if ($smwgIQRedirectNormalization) { |
| 1146 | + global $smwgQEqualitySupport; |
| 1147 | + if ($smwgQEqualitySupport) { |
1083 | 1148 | $page = $this->getRedirectTarget($description->getIndividual(), $db); |
1084 | 1149 | } else { |
1085 | 1150 | $page = $description->getIndividual(); |
— | — | @@ -1088,7 +1153,7 @@ |
1089 | 1154 | $db->addQuotes($page->getDBKey()) . ' AND ' . |
1090 | 1155 | $curtables['PREVREL'] . '.object_namespace=' . |
1091 | 1156 | $page->getNamespace(); |
1092 | | - if ( $smwgIQRedirectNormalization && ($this->addInnerJoin('REDIRECT', $from, $db, $curtables)) ) { |
| 1157 | + if ( $smwgQEqualitySupport && ($this->addJoin('REDIRECT', $from, $db, $curtables)) ) { |
1093 | 1158 | $cond = '(' . $cond . ') OR (' . |
1094 | 1159 | $curtables['REDIRECT'] . '.rd_title=' . |
1095 | 1160 | $db->addQuotes($page->getDBKey()) . ' AND ' . |
— | — | @@ -1096,7 +1161,7 @@ |
1097 | 1162 | $page->getNamespace() . ')'; |
1098 | 1163 | } |
1099 | 1164 | $where .= $cond; |
1100 | | - } elseif ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { |
| 1165 | + } elseif ($this->addJoin('PAGE', $from, $db, $curtables)) { |
1101 | 1166 | $where .= $curtables['PAGE'] . '.page_title=' . |
1102 | 1167 | $db->addQuotes($page->getDBKey()) . ' AND ' . |
1103 | 1168 | $curtables['PAGE'] . '.page_namespace=' . |
— | — | @@ -1107,7 +1172,7 @@ |
1108 | 1173 | case 'text': // actually this should not happen; we cannot do anything here |
1109 | 1174 | break; |
1110 | 1175 | default: |
1111 | | - if ( $this->addInnerJoin('ATTS', $from, $db, $curtables) ) { |
| 1176 | + if ( $this->addJoin('ATTS', $from, $db, $curtables) ) { |
1112 | 1177 | switch ($description->getComparator()) { |
1113 | 1178 | case SMW_CMP_EQ: $op = '='; break; |
1114 | 1179 | case SMW_CMP_LEQ: $op = '<='; break; |
— | — | @@ -1137,7 +1202,7 @@ |
1138 | 1203 | $nexttables = array(); |
1139 | 1204 | // pull in page to prevent every child description pulling it seperately! |
1140 | 1205 | /// TODO: will be obsolete when PREVREL provides page indices |
1141 | | - if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { |
| 1206 | + if ($this->addJoin('PAGE', $from, $db, $curtables)) { |
1142 | 1207 | $nexttables['PAGE'] = $curtables['PAGE']; |
1143 | 1208 | } |
1144 | 1209 | if (array_key_exists('PREVREL',$curtables)) { |
— | — | @@ -1164,9 +1229,16 @@ |
1165 | 1230 | } |
1166 | 1231 | } |
1167 | 1232 | } elseif ($description instanceof SMWSomeRelation) { |
1168 | | - if ($this->addInnerJoin('RELS', $from, $db, $curtables)) { |
1169 | | - $where .= $curtables['RELS'] . '.relation_title=' . |
1170 | | - $db->addQuotes($description->getRelation()->getDBKey()); |
| 1233 | + if ($this->addJoin('RELS', $from, $db, $curtables)) { |
| 1234 | + global $smwgQSubpropertyDepth; |
| 1235 | + if ($smwgQSubpropertyDepth > 0) { |
| 1236 | + $pt = $this->getPropertyTable($description->getRelation()->getDBKey(), $db); |
| 1237 | + $from = '`' . $pt . '`, ' . $from; |
| 1238 | + $where = "$pt.title=" . $curtables['RELS'] . '.relation_title'; |
| 1239 | + } else { |
| 1240 | + $where .= $curtables['RELS'] . '.relation_title=' . |
| 1241 | + $db->addQuotes($description->getRelation()->getDBKey()); |
| 1242 | + } |
1171 | 1243 | $nexttables = array( 'PREVREL' => $curtables['RELS'] ); |
1172 | 1244 | $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $nexttables, ($this->m_sortkey == $description->getRelation()->getDBKey()) ); |
1173 | 1245 | if ( $subwhere != '') { |
— | — | @@ -1177,21 +1249,29 @@ |
1178 | 1250 | $id = SMWDataValueFactory::getAttributeObjectTypeID($description->getAttribute()); |
1179 | 1251 | switch ($id) { |
1180 | 1252 | case 'text': |
1181 | | - if ($this->addInnerJoin('TEXT', $from, $db, $curtables)) { |
1182 | | - $where .= $curtables['TEXT'] . '.attribute_title=' . |
1183 | | - $db->addQuotes($description->getAttribute()->getDBKey()); |
1184 | | - // no recursion: we do not support further conditions on text-type values |
1185 | | - } |
| 1253 | + $table = 'TEXT'; |
| 1254 | + $sub = false; //no recursion: we do not support further conditions on text-type values |
1186 | 1255 | break; |
1187 | 1256 | default: |
1188 | | - if ($this->addInnerJoin('ATTS', $from, $db, $curtables)) { |
1189 | | - $where .= $curtables['ATTS'] . '.attribute_title=' . |
1190 | | - $db->addQuotes($description->getAttribute()->getDBKey()); |
1191 | | - $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $curtables, ($this->m_sortkey == $description->getAttribute()->getDBKey()) ); |
1192 | | - if ( $subwhere != '') { |
1193 | | - $where .= ' AND (' . $subwhere . ')'; |
1194 | | - } |
| 1257 | + $table = 'ATTS'; |
| 1258 | + $sub = true; |
| 1259 | + } |
| 1260 | + if ($this->addJoin($table, $from, $db, $curtables)) { |
| 1261 | + global $smwgQSubpropertyDepth; |
| 1262 | + if ($smwgQSubpropertyDepth > 0) { |
| 1263 | + $pt = $this->getPropertyTable($description->getAttribute()->getDBKey(), $db); |
| 1264 | + $from = '`' . $pt . '`, ' . $from; |
| 1265 | + $where = "$pt.title=" . $curtables[$table] . '.attribute_title'; |
| 1266 | + } else { |
| 1267 | + $where .= $curtables[$table] . '.attribute_title=' . |
| 1268 | + $db->addQuotes($description->getAttribute()->getDBKey()); |
| 1269 | + } |
| 1270 | + if ($sub) { |
| 1271 | + $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $curtables, ($this->m_sortkey == $description->getAttribute()->getDBKey()) ); |
| 1272 | + if ( $subwhere != '') { |
| 1273 | + $where .= ' AND (' . $subwhere . ')'; |
1195 | 1274 | } |
| 1275 | + } |
1196 | 1276 | } |
1197 | 1277 | } |
1198 | 1278 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php |
— | — | @@ -55,6 +55,12 @@ |
56 | 56 | # Settings for inline queries (<ask>) and for semantic queries in general. |
57 | 57 | # Especially meant to prevent overly high server-load by complex queries. |
58 | 58 | ## |
| 59 | +$smwgQSubcategoryDepth = 10; // Restrict level of sub-category inclusion (steps within category hierarchy) |
| 60 | +$smwgQSubpropertyDepth = 10; // Restrict level of sub-property inclusion (steps within category hierarchy) |
| 61 | +// (Use 0 to disable hierarchy-inferencing in queries) |
| 62 | +$smwgQEqualitySupport = true; // Should #redirects be evaluated as equality between page names? |
| 63 | + |
| 64 | +## older query parameters below, some of those might be ignored |
59 | 65 | $smwgIQEnabled = true; // (De)activates all query related features |
60 | 66 | $smwgIQDefaultLinking = 'subject'; // Default linking behaviour. Can be one of "none", "subject", "all" |
61 | 67 | $smwgIQSearchNamespaces = array(NS_MAIN, NS_IMAGE); // Which namespaces should be searched by default? |
— | — | @@ -67,9 +73,7 @@ |
68 | 74 | $smwgIQMaxInlineLimit = 500; // Max number of rows printed in an inline query on a single page. |
69 | 75 | $smwgIQDefaultLimit = 50; // Default number of rows returned in a query. Can be increased with <ask limit="num">... |
70 | 76 | $smwgIQDisjunctiveQueriesEnabled = true; // Support disjunctions in queries (||)? |
71 | | -$smwgIQSubcategoryInclusions = 10; // Restrict level of sub-category inclusion (steps within category hierarchy) |
72 | | - // Use 0 to disable hierarchy-inferencing in queries |
73 | | -$smwgIQRedirectNormalization = true; // Should redirects be interpreted as equivalence between page names? |
| 77 | +//$smwgIQRedirectNormalization = true; // Should redirects be interpreted as equivalence between page names? |
74 | 78 | $smwgIQSortingEnabled = true; // (De)activate sorting of results. |
75 | 79 | ## |
76 | 80 | |