1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Improve browsability of Projects query

Summary:
Ref T5750. Same deal as D12427, but for projects.

(As before, mostly making the empty/browse view work instead of return nothing.)

Test Plan: {F372353}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5750

Differential Revision: https://secure.phabricator.com/D12428
This commit is contained in:
epriestley 2015-04-15 11:49:07 -07:00
parent fd60a739c1
commit c8dc11d81a
3 changed files with 26 additions and 29 deletions

View file

@ -9,7 +9,7 @@ final class PhabricatorProjectQuery
private $slugs; private $slugs;
private $phrictionSlugs; private $phrictionSlugs;
private $names; private $names;
private $datasourceQuery; private $nameTokens;
private $icons; private $icons;
private $colors; private $colors;
@ -60,8 +60,8 @@ final class PhabricatorProjectQuery
return $this; return $this;
} }
public function withDatasourceQuery($string) { public function withNameTokens(array $tokens) {
$this->datasourceQuery = $string; $this->nameTokens = array_values($tokens);
return $this; return $this;
} }
@ -329,7 +329,7 @@ final class PhabricatorProjectQuery
} }
private function buildGroupClause($conn_r) { private function buildGroupClause($conn_r) {
if ($this->memberPHIDs || $this->datasourceQuery) { if ($this->memberPHIDs || $this->nameTokens) {
return 'GROUP BY p.id'; return 'GROUP BY p.id';
} else { } else {
return $this->buildApplicationSearchGroupClause($conn_r); return $this->buildApplicationSearchGroupClause($conn_r);
@ -363,23 +363,18 @@ final class PhabricatorProjectQuery
id(new PhabricatorProjectSlug())->getTableName()); id(new PhabricatorProjectSlug())->getTableName());
} }
if ($this->datasourceQuery !== null) { if ($this->nameTokens !== null) {
$tokens = PhabricatorTypeaheadDatasource::tokenizeString( foreach ($this->nameTokens as $key => $token) {
$this->datasourceQuery); $token_table = 'token_'.$key;
if (!$tokens) { $joins[] = qsprintf(
throw new PhabricatorEmptyQueryException(); $conn_r,
'JOIN %T %T ON %T.projectID = p.id AND %T.token LIKE %>',
PhabricatorProject::TABLE_DATASOURCE_TOKEN,
$token_table,
$token_table,
$token_table,
$token);
} }
$likes = array();
foreach ($tokens as $token) {
$likes[] = qsprintf($conn_r, 'token.token LIKE %>', $token);
}
$joins[] = qsprintf(
$conn_r,
'JOIN %T token ON token.projectID = p.id AND (%Q)',
PhabricatorProject::TABLE_DATASOURCE_TOKEN,
'('.implode(') OR (', $likes).')');
} }
$joins[] = $this->buildApplicationSearchJoinClause($conn_r); $joins[] = $this->buildApplicationSearchJoinClause($conn_r);

View file

@ -55,7 +55,8 @@ final class PhabricatorProjectSearchEngine
$name = $saved->getParameter('name'); $name = $saved->getParameter('name');
if (strlen($name)) { if (strlen($name)) {
$query->withDatasourceQuery($name); $tokens = PhabricatorTypeaheadDatasource::tokenizeString($name);
$query->withNameTokens($tokens);
} }
$icons = $saved->getParameter('icons'); $icons = $saved->getParameter('icons');

View file

@ -18,17 +18,18 @@ final class PhabricatorProjectDatasource
// Allow users to type "#qa" or "qa" to find "Quality Assurance". // Allow users to type "#qa" or "qa" to find "Quality Assurance".
$raw_query = ltrim($raw_query, '#'); $raw_query = ltrim($raw_query, '#');
$tokens = self::tokenizeString($raw_query);
if (!strlen($raw_query)) { $query = id(new PhabricatorProjectQuery())
return array(); ->needImages(true)
->needSlugs(true);
if ($tokens) {
$query->withNameTokens($tokens);
} }
$projs = id(new PhabricatorProjectQuery()) $projs = $this->executeQuery($query);
->setViewer($viewer)
->needImages(true)
->needSlugs(true)
->withDatasourceQuery($raw_query)
->execute();
$projs = mpull($projs, null, 'getPHID'); $projs = mpull($projs, null, 'getPHID');
$must_have_cols = $this->getParameter('mustHaveColumns', false); $must_have_cols = $this->getParameter('mustHaveColumns', false);