Commit 9ec4cfb3d20b7c2f6d3f9ae854991d306abc6a9d
Merge branch 'master' of git@github.com:ktgit/knowledgetree
Showing
5 changed files
with
75 additions
and
5 deletions
search2/search/expr.inc.php
| @@ -1079,6 +1079,7 @@ class SQLQueryBuilder implements QueryBuilder | @@ -1079,6 +1079,7 @@ class SQLQueryBuilder implements QueryBuilder | ||
| 1079 | if (array_key_exists($tablename, $this->used_tables)) | 1079 | if (array_key_exists($tablename, $this->used_tables)) |
| 1080 | { | 1080 | { |
| 1081 | $this->used_tables[$tablename]++; | 1081 | $this->used_tables[$tablename]++; |
| 1082 | + if (isset($expr->references)) ++$expr->references; | ||
| 1082 | } | 1083 | } |
| 1083 | } | 1084 | } |
| 1084 | } | 1085 | } |
| @@ -1244,7 +1245,18 @@ class SQLQueryBuilder implements QueryBuilder | @@ -1244,7 +1245,18 @@ class SQLQueryBuilder implements QueryBuilder | ||
| 1244 | } | 1245 | } |
| 1245 | if ($this->used_tables['document_fields_link'] > 0) | 1246 | if ($this->used_tables['document_fields_link'] > 0) |
| 1246 | { | 1247 | { |
| 1247 | - $sql .= ' LEFT JOIN document_fields_link pdfl ON dmv.id=pdfl.metadata_version_id ' . "\n"; | 1248 | + // NOTE this is a bit of a hack, maybe? or maybe it really is the best way? |
| 1249 | + // ...what about using the loop below which checks the expression | ||
| 1250 | + // for a join table rather than this up here? - otherwise this only | ||
| 1251 | + // affects this particular query type - then again maybe that's what we want... | ||
| 1252 | + for ($i = 0; $i < $this->used_tables['document_fields_link']; ++$i) | ||
| 1253 | + { | ||
| 1254 | + if ($i > 0) $counter = $i; | ||
| 1255 | + else $counter = ''; | ||
| 1256 | + | ||
| 1257 | + $sql .= ' LEFT JOIN document_fields_link pdfl' . $counter . ' ' | ||
| 1258 | + . 'ON dmv.id=pdfl' . $counter . '.metadata_version_id ' . "\n"; | ||
| 1259 | + } | ||
| 1248 | } | 1260 | } |
| 1249 | 1261 | ||
| 1250 | if ($this->used_tables['tag_words'] > 0) | 1262 | if ($this->used_tables['tag_words'] > 0) |
| @@ -1374,7 +1386,6 @@ class SQLQueryBuilder implements QueryBuilder | @@ -1374,7 +1386,6 @@ class SQLQueryBuilder implements QueryBuilder | ||
| 1374 | 1386 | ||
| 1375 | public function buildComplexQuery($expr) | 1387 | public function buildComplexQuery($expr) |
| 1376 | { | 1388 | { |
| 1377 | -// print "building complex \n\n"; | ||
| 1378 | $this->exploreExprs($expr); | 1389 | $this->exploreExprs($expr); |
| 1379 | 1390 | ||
| 1380 | $sql = $this->buildCoreSQL(); | 1391 | $sql = $this->buildCoreSQL(); |
| @@ -1396,7 +1407,6 @@ class SQLQueryBuilder implements QueryBuilder | @@ -1396,7 +1407,6 @@ class SQLQueryBuilder implements QueryBuilder | ||
| 1396 | 1407 | ||
| 1397 | public function buildSimpleQuery($op, $group) | 1408 | public function buildSimpleQuery($op, $group) |
| 1398 | { | 1409 | { |
| 1399 | -// print "building simple \n\n"; | ||
| 1400 | $this->exploreGroup($group); | 1410 | $this->exploreGroup($group); |
| 1401 | 1411 | ||
| 1402 | $sql = $this->buildCoreSQL(); | 1412 | $sql = $this->buildCoreSQL(); |
search2/search/fields/AnyMetadataField.inc.php
| @@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
| 40 | class AnyMetadataField extends DBFieldExpr | 40 | class AnyMetadataField extends DBFieldExpr |
| 41 | { | 41 | { |
| 42 | public $general_op = ExprOp::CONTAINS; | 42 | public $general_op = ExprOp::CONTAINS; |
| 43 | - | 43 | + public $references = 0; |
| 44 | 44 | ||
| 45 | public function __construct() | 45 | public function __construct() |
| 46 | { | 46 | { |
| @@ -48,6 +48,34 @@ class AnyMetadataField extends DBFieldExpr | @@ -48,6 +48,34 @@ class AnyMetadataField extends DBFieldExpr | ||
| 48 | $this->setAlias('Metadata'); | 48 | $this->setAlias('Metadata'); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | + /* | ||
| 52 | + * Overridden function to adjust table alias in cases of | ||
| 53 | + * the document_fields_link table being included more than once | ||
| 54 | + * | ||
| 55 | + * NOTE this only works in conjunction with code in expr.inc.php which adds the left joins to the db query. | ||
| 56 | + * I don't like this and think we should look for a way to make the table joining more generic | ||
| 57 | + * such that it can be controlled via these classes and thereby contained as a unit. | ||
| 58 | + */ | ||
| 59 | + public function modifyName($name) | ||
| 60 | + { | ||
| 61 | + if ($this->references > 0) | ||
| 62 | + { | ||
| 63 | + static $count = 0; | ||
| 64 | + if ($count >= $this->references) | ||
| 65 | + { | ||
| 66 | + $count = 0; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + if ((($pos = strpos($name, '.')) !== false) && ($count != 0)) | ||
| 70 | + { | ||
| 71 | + $name = substr($name, 0, $pos) . $count . substr($name, $pos); | ||
| 72 | + } | ||
| 73 | + ++$count; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + return $name; | ||
| 77 | + } | ||
| 78 | + | ||
| 51 | public function getInputRequirements() | 79 | public function getInputRequirements() |
| 52 | { | 80 | { |
| 53 | return array('value'=>array('type'=>FieldInputType::TEXT)); | 81 | return array('value'=>array('type'=>FieldInputType::TEXT)); |
search2/search/fields/TitleField.inc.php
| @@ -39,6 +39,8 @@ | @@ -39,6 +39,8 @@ | ||
| 39 | 39 | ||
| 40 | class TitleField extends DBFieldExpr | 40 | class TitleField extends DBFieldExpr |
| 41 | { | 41 | { |
| 42 | + public $general_op = ExprOp::CONTAINS; | ||
| 43 | + | ||
| 42 | public function __construct() | 44 | public function __construct() |
| 43 | { | 45 | { |
| 44 | parent::__construct('name', 'document_metadata_version', _kt('Title')); | 46 | parent::__construct('name', 'document_metadata_version', _kt('Title')); |
sql/mysql/install/data.sql
| @@ -1407,8 +1407,9 @@ INSERT INTO `search_ranking` VALUES | @@ -1407,8 +1407,9 @@ INSERT INTO `search_ranking` VALUES | ||
| 1407 | ('DocumentText','',100,'S'), | 1407 | ('DocumentText','',100,'S'), |
| 1408 | ('document_content_version','filename',10,'T'), | 1408 | ('document_content_version','filename',10,'T'), |
| 1409 | ('document_content_version','filesize',1,'T'), | 1409 | ('document_content_version','filesize',1,'T'), |
| 1410 | +('document_fields_link','value',1,'T'), | ||
| 1410 | ('document_metadata_version','document_type_id',1,'T'), | 1411 | ('document_metadata_version','document_type_id',1,'T'), |
| 1411 | -('document_metadata_version','name',1,'T'), | 1412 | +('document_metadata_version','name',300,'T'), |
| 1412 | ('document_metadata_version','workflow_id',1,'T'), | 1413 | ('document_metadata_version','workflow_id',1,'T'), |
| 1413 | ('document_metadata_version','workflow_state_id',1,'T'), | 1414 | ('document_metadata_version','workflow_state_id',1,'T'), |
| 1414 | ('tag_words','tag',1,'T'); | 1415 | ('tag_words','tag',1,'T'); |
sql/mysql/upgrade/3.6.1/search_ranking.sql
0 → 100644
| 1 | +CREATE TABLE `search_ranking` ( | ||
| 2 | + `groupname` varchar(100) NOT NULL, | ||
| 3 | + `itemname` varchar(100) NOT NULL, | ||
| 4 | + `ranking` float default '0', | ||
| 5 | + `type` enum('T','M','S') default 'T' COMMENT 'T=Table, M=Metadata, S=Searchable', | ||
| 6 | + PRIMARY KEY (`groupname`,`itemname`) | ||
| 7 | +) ENGINE=innodb DEFAULT CHARSET=utf8; | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +INSERT INTO `search_ranking` VALUES | ||
| 11 | + ('Discussion','',150,'S'), | ||
| 12 | + ('documents','checked_out_user_id',1,'T'), | ||
| 13 | + ('documents','created',1,'T'), | ||
| 14 | + ('documents','creator_id',1,'T'), | ||
| 15 | + ('documents','id',1,'T'), | ||
| 16 | + ('documents','immutable',1,'T'), | ||
| 17 | + ('documents','is_checked_out',1,'T'), | ||
| 18 | + ('documents','modified',1,'T'), | ||
| 19 | + ('documents','modified_user_id',1,'T'), | ||
| 20 | + ('documents','title',300,'T'), | ||
| 21 | + ('DocumentText','',100,'S'), | ||
| 22 | + ('document_content_version','filename',10,'T'), | ||
| 23 | + ('document_content_version','filesize',1,'T'), | ||
| 24 | + ('document_fields_link','value',1,'T'), | ||
| 25 | + ('document_metadata_version','document_type_id',1,'T'), | ||
| 26 | + ('document_metadata_version','name',300,'T'), | ||
| 27 | + ('document_metadata_version','workflow_id',1,'T'), | ||
| 28 | + ('document_metadata_version','workflow_state_id',1,'T'), | ||
| 29 | + ('tag_words','tag',1,'T'); | ||
| 0 | \ No newline at end of file | 30 | \ No newline at end of file |