Path: blob/master/src/applications/conpherence/query/ConpherenceFulltextQuery.php
12256 views
<?php12final class ConpherenceFulltextQuery3extends PhabricatorOffsetPagedQuery {45private $threadPHIDs;6private $previousTransactionPHIDs;7private $fulltext;89public function withThreadPHIDs(array $phids) {10$this->threadPHIDs = $phids;11return $this;12}1314public function withPreviousTransactionPHIDs(array $phids) {15$this->previousTransactionPHIDs = $phids;16return $this;17}1819public function withFulltext($fulltext) {20$this->fulltext = $fulltext;21return $this;22}2324public function execute() {25$table = new ConpherenceIndex();26$conn_r = $table->establishConnection('r');2728$rows = queryfx_all(29$conn_r,30'SELECT threadPHID, transactionPHID, previousTransactionPHID31FROM %T i %Q %Q %Q',32$table->getTableName(),33$this->buildWhereClause($conn_r),34$this->buildOrderByClause($conn_r),35$this->buildLimitClause($conn_r));3637return $rows;38}3940protected function buildWhereClause(AphrontDatabaseConnection $conn) {41$where = array();4243if ($this->threadPHIDs !== null) {44$where[] = qsprintf(45$conn,46'i.threadPHID IN (%Ls)',47$this->threadPHIDs);48}4950if ($this->previousTransactionPHIDs !== null) {51$where[] = qsprintf(52$conn,53'i.previousTransactionPHID IN (%Ls)',54$this->previousTransactionPHIDs);55}5657if (strlen($this->fulltext)) {58$compiler = PhabricatorSearchDocument::newQueryCompiler();59$tokens = $compiler->newTokens($this->fulltext);60$compiled_query = $compiler->compileQuery($tokens);6162$where[] = qsprintf(63$conn,64'MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE)',65$compiled_query);66}6768return $this->formatWhereClause($conn, $where);69}7071private function buildOrderByClause(AphrontDatabaseConnection $conn_r) {72if (strlen($this->fulltext)) {73return qsprintf(74$conn_r,75'ORDER BY MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE) DESC',76$this->fulltext);77} else {78return qsprintf(79$conn_r,80'ORDER BY id DESC');81}82}8384}858687