Differential D19814 Diff 47316 src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
| Show First 20 Lines • Show All 1,434 Lines • ▼ Show 20 Lines | foreach ($vector as $order) { | ||||
| $table, | $table, | ||||
| $alias, | $alias, | ||||
| $alias, | $alias, | ||||
| $phid_column, | $phid_column, | ||||
| $alias, | $alias, | ||||
| $key); | $key); | ||||
| } | } | ||||
| return implode(' ', $joins); | if ($joins) { | ||||
| return qsprintf($conn, '%LJ', $joins); | |||||
| } else { | |||||
| return qsprintf($conn, ''); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| * Construct a WHERE clause appropriate for applying ApplicationSearch | * Construct a WHERE clause appropriate for applying ApplicationSearch | ||||
| * constraints. | * constraints. | ||||
| * | * | ||||
| * @param AphrontDatabaseConnection Connection executing the query. | * @param AphrontDatabaseConnection Connection executing the query. | ||||
| * @return list<string> Where clause parts. | * @return list<string> Where clause parts. | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | foreach ($this->applicationSearchConstraints as $key => $constraint) { | ||||
| 'index of type "%s".', | 'index of type "%s".', | ||||
| $op, | $op, | ||||
| $type)); | $type)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if ($constraint_parts) { | if ($constraint_parts) { | ||||
| $where[] = '('.implode(') OR (', $constraint_parts).')'; | $where[] = qsprintf($conn, '%LO', $constraint_parts); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | protected function buildFerretSelectClause(AphrontDatabaseConnection $conn) { | ||||
| $vector = $this->getOrderVector(); | $vector = $this->getOrderVector(); | ||||
| if (!$vector->containsKey('rank')) { | if (!$vector->containsKey('rank')) { | ||||
| // We only need to SELECT the virtual "_ft_rank" column if we're | // We only need to SELECT the virtual "_ft_rank" column if we're | ||||
| // actually sorting the results by rank. | // actually sorting the results by rank. | ||||
| return $select; | return $select; | ||||
| } | } | ||||
| if (!$this->ferretEngine) { | if (!$this->ferretEngine) { | ||||
| $select[] = '0 _ft_rank'; | $select[] = qsprintf($conn, '0 _ft_rank'); | ||||
| return $select; | return $select; | ||||
| } | } | ||||
| $engine = $this->ferretEngine; | $engine = $this->ferretEngine; | ||||
| $stemmer = $engine->newStemmer(); | $stemmer = $engine->newStemmer(); | ||||
| $op_sub = PhutilSearchQueryCompiler::OPERATOR_SUBSTRING; | $op_sub = PhutilSearchQueryCompiler::OPERATOR_SUBSTRING; | ||||
| $op_not = PhutilSearchQueryCompiler::OPERATOR_NOT; | $op_not = PhutilSearchQueryCompiler::OPERATOR_NOT; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | foreach ($this->ferretTokens as $fulltext_token) { | ||||
| $parts[] = qsprintf( | $parts[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'IF(%T.normalCorpus LIKE %~, 1, 0)', | 'IF(%T.normalCorpus LIKE %~, 1, 0)', | ||||
| $table_alias, | $table_alias, | ||||
| $stem_value); | $stem_value); | ||||
| } | } | ||||
| } | } | ||||
| $parts[] = '0'; | $parts[] = qsprintf($conn, '%d', 0); | ||||
| $sum = array_shift($parts); | |||||
| foreach ($parts as $part) { | |||||
| $sum = qsprintf( | |||||
| $conn, | |||||
| '%Q + %Q', | |||||
amckinley: We clearly need an`%L+` operator for this extremely common pattern. | |||||
| $sum, | |||||
| $part); | |||||
| } | |||||
| $select[] = qsprintf( | $select[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q _ft_rank', | '%Q _ft_rank', | ||||
| implode(' + ', $parts)); | $sum); | ||||
| return $select; | return $select; | ||||
| } | } | ||||
| protected function buildFerretJoinClause(AphrontDatabaseConnection $conn) { | protected function buildFerretJoinClause(AphrontDatabaseConnection $conn) { | ||||
| if (!$this->ferretEngine) { | if (!$this->ferretEngine) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | foreach ($this->ferretTokens as $fulltext_token) { | ||||
| '(%T.normalCorpus LIKE %~)', | '(%T.normalCorpus LIKE %~)', | ||||
| $table_alias, | $table_alias, | ||||
| $stem_value); | $stem_value); | ||||
| } | } | ||||
| if ($is_not) { | if ($is_not) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '(%Q)', | '%LA', | ||||
| implode(' AND ', $term_constraints)); | $term_constraints); | ||||
| } else if ($is_quoted) { | } else if ($is_quoted) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '(%T.rawCorpus LIKE %~ AND (%Q))', | '(%T.rawCorpus LIKE %~ AND %LO)', | ||||
| $table_alias, | $table_alias, | ||||
| $value, | $value, | ||||
| implode(' OR ', $term_constraints)); | $term_constraints); | ||||
| } else { | } else { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '(%Q)', | '%LO', | ||||
| implode(' OR ', $term_constraints)); | $term_constraints); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->ferretQuery) { | if ($this->ferretQuery) { | ||||
| $query = $this->ferretQuery; | $query = $this->ferretQuery; | ||||
| $author_phids = $query->getParameter('authorPHIDs'); | $author_phids = $query->getParameter('authorPHIDs'); | ||||
| if ($author_phids) { | if ($author_phids) { | ||||
| ▲ Show 20 Lines • Show All 887 Lines • Show Last 20 Lines | |||||
We clearly need an`%L+` operator for this extremely common pattern.