@@ -14,48 +14,40 @@ class SearchCloud extends SearchConfig
14
14
protected $ limit = '' ;
15
15
16
16
/**
17
- * Transform the set search parameters into a statement
17
+ * We do not have pagination in clouds, so we can work with a limit within SQL
18
18
*
19
- * @return array ($sql, $opts) The SQL and parameters to execute
19
+ * @param int $limit
20
20
*/
21
- public function getSQL ( )
21
+ public function setLimit ( $ limit )
22
22
{
23
- if (!$ this ->columns ) throw new StructException ('nocolname ' );
24
-
25
- $ QB = new QueryBuilder ();
26
- reset ($ this ->schemas );
27
- $ schema = current ($ this ->schemas );
28
- $ datatable = 'data_ ' . $ schema ->getTable ();
29
-
30
- $ QB ->addTable ($ datatable );
31
-
32
- // add conditional page clauses if pid has a value
33
- $ subAnd = $ QB ->filters ()->whereSubAnd ();
34
- $ subAnd ->whereAnd ("$ datatable.pid = '' " );
35
-
36
- $ subOr = $ subAnd ->whereSubOr ();
37
- $ subOr ->whereAnd ("GETACCESSLEVEL( $ datatable.pid) > 0 " );
38
- $ subOr ->whereAnd ("PAGEEXISTS( $ datatable.pid) = 1 " );
39
- $ subOr ->whereSubOr ()
40
- ->whereAnd ('ASSIGNED == 1 ' )
41
- ->whereSubOr ()
42
- ->whereAnd ("$ datatable.rid > 0 " )
43
- ->whereAnd ("ASSIGNED IS NULL " );
44
-
45
- // add conditional schema assignment check
46
- $ QB ->addLeftJoin (
47
- $ datatable ,
48
- 'schema_assignments ' ,
49
- '' ,
50
- "$ datatable.pid != ''
51
- AND $ datatable.pid = schema_assignments.pid
52
- AND schema_assignments.tbl = ' {$ schema ->getTable ()}' "
53
- );
54
-
55
- $ QB ->filters ()->whereAnd ("$ datatable.latest = 1 " );
56
- $ QB ->filters ()->where ('AND ' , 'tag IS NOT \'\'' );
23
+ $ this ->limit = " LIMIT $ limit " ;
24
+ }
25
+
26
+ /**
27
+ * @inheritdoc
28
+ */
29
+ protected function runSQLBuilder ()
30
+ {
31
+ $ sqlBuilder = new SearchSQLBuilder ();
32
+ $ sqlBuilder ->setSelectLatest ($ this ->selectLatest );
33
+ $ sqlBuilder ->addSchemas ($ this ->schemas , false );
34
+ $ this ->addTagSelector ($ sqlBuilder );
35
+ $ sqlBuilder ->getQueryBuilder ()->addGroupByStatement ('tag ' );
36
+ $ sqlBuilder ->getQueryBuilder ()->addOrderBy ('count DESC ' );
37
+ $ sqlBuilder ->addFilters ($ this ->filter );
38
+ return $ sqlBuilder ;
39
+ }
40
+
41
+ /**
42
+ * Add the tag selector to the SQLBuilder
43
+ */
44
+ protected function addTagSelector (SearchSQLBuilder $ builder )
45
+ {
46
+ $ QB = $ builder ->getQueryBuilder ();
57
47
58
48
$ col = $ this ->columns [0 ];
49
+ $ datatable = "data_ {$ col ->getTable ()}" ;
50
+
59
51
if ($ col ->isMulti ()) {
60
52
$ multitable = "multi_ {$ col ->getTable ()}" ;
61
53
$ MN = $ QB ->generateTableAlias ('M ' );
@@ -77,23 +69,8 @@ public function getSQL()
77
69
$ colname = $ datatable . '. ' . $ col ->getColName ();
78
70
}
79
71
$ QB ->addSelectStatement ("COUNT( $ colname) " , 'count ' );
80
- $ QB ->addSelectColumn ('schema_assignments ' , 'assigned ' , 'ASSIGNED ' );
81
- $ QB ->addGroupByStatement ('tag ' );
82
- $ QB ->addOrderBy ('count DESC ' );
83
-
84
- [$ sql , $ opts ] = $ QB ->getSQL ();
85
- return [$ sql . $ this ->limit , $ opts ];
86
72
}
87
73
88
- /**
89
- * We do not have pagination in clouds, so we can work with a limit within SQL
90
- *
91
- * @param int $limit
92
- */
93
- public function setLimit ($ limit )
94
- {
95
- $ this ->limit = " LIMIT $ limit " ;
96
- }
97
74
98
75
/**
99
76
* Execute this search and return the result
0 commit comments