Skip to content

Commit 7923cda

Browse files
committed
allow preset filters and related schemas for cloud
This refactors the cloud aggregation to make use of the SearchSQLBuilder, this in turn allows for reusing much but not all of the default parameter handling. By allowing joins (on pid) and setting filters we can output clouds based on the same data as a shown aggregation.
1 parent fa5b7b6 commit 7923cda

File tree

4 files changed

+39
-63
lines changed

4 files changed

+39
-63
lines changed

lang/en/lang.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
$lang['Exception no sqlite'] = 'The struct plugin requires the sqlite plugin. Please install and enable it.';
8282
$lang['Exception column not in table'] = 'There is no column %s in schema %s.';
8383
$lang['Exception datefilter'] = 'The filter: \'<code>$Date(%s)$</code>\' contains an unsupported value.';
84-
$lang['Warning: no filters for cloud'] = 'Filters are not supported for struct clouds.';
8584
$lang['sort'] = 'Sort by this column';
8685
$lang['next'] = 'Next page';
8786
$lang['prev'] = 'Previous page';

meta/SearchCloud.php

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,40 @@ class SearchCloud extends SearchConfig
1414
protected $limit = '';
1515

1616
/**
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
1818
*
19-
* @return array ($sql, $opts) The SQL and parameters to execute
19+
* @param int $limit
2020
*/
21-
public function getSQL()
21+
public function setLimit($limit)
2222
{
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();
5747

5848
$col = $this->columns[0];
49+
$datatable = "data_{$col->getTable()}";
50+
5951
if ($col->isMulti()) {
6052
$multitable = "multi_{$col->getTable()}";
6153
$MN = $QB->generateTableAlias('M');
@@ -77,23 +69,8 @@ public function getSQL()
7769
$colname = $datatable . '.' . $col->getColName();
7870
}
7971
$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];
8672
}
8773

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-
}
9774

9875
/**
9976
* Execute this search and return the result

meta/SearchSQLBuilder.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public function __construct()
2727
* Add the schemas to the query
2828
*
2929
* @param Schema[] $schemas Schema names to query
30+
* @param bool $selectMeta Select meta columns (pid, rid, rev, assigned)
3031
*/
31-
public function addSchemas($schemas)
32+
public function addSchemas($schemas, $selectMeta = true)
3233
{
3334
// basic tables
3435
$first_table = '';
@@ -60,12 +61,14 @@ public function addSchemas($schemas)
6061
AND schema_assignments.tbl = '{$schema->getTable()}'"
6162
);
6263

63-
$this->qb->addSelectColumn($datatable, 'rid');
64-
$this->qb->addSelectColumn($datatable, 'pid', 'PID');
65-
$this->qb->addSelectColumn($datatable, 'rev');
66-
$this->qb->addSelectColumn('schema_assignments', 'assigned', 'ASSIGNED');
67-
$this->qb->addGroupByColumn($datatable, 'pid');
68-
$this->qb->addGroupByColumn($datatable, 'rid');
64+
if ($selectMeta) {
65+
$this->qb->addSelectColumn($datatable, 'rid');
66+
$this->qb->addSelectColumn($datatable, 'pid', 'PID');
67+
$this->qb->addSelectColumn($datatable, 'rev');
68+
$this->qb->addSelectColumn('schema_assignments', 'assigned', 'ASSIGNED');
69+
$this->qb->addGroupByColumn($datatable, 'pid');
70+
$this->qb->addGroupByColumn($datatable, 'rid');
71+
}
6972

7073
$first_table = $datatable;
7174
}

syntax/cloud.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ public function render($mode, Doku_Renderer $renderer, $data)
8888
{
8989
if ($mode != 'xhtml') return false;
9090
if (!$data) return false;
91-
if (!empty($data['filter'])) {
92-
msg($this->getLang('Warning: no filters for cloud'), -1);
93-
}
9491
global $INFO, $conf;
9592
try {
9693
$search = new SearchCloud($data);

0 commit comments

Comments
 (0)