@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 85 lines 2.1 kB view raw
1<?php 2 3final class ConpherenceFulltextQuery 4 extends PhabricatorOffsetPagedQuery { 5 6 private $threadPHIDs; 7 private $previousTransactionPHIDs; 8 private $fulltext; 9 10 public function withThreadPHIDs(array $phids) { 11 $this->threadPHIDs = $phids; 12 return $this; 13 } 14 15 public function withPreviousTransactionPHIDs(array $phids) { 16 $this->previousTransactionPHIDs = $phids; 17 return $this; 18 } 19 20 public function withFulltext($fulltext) { 21 $this->fulltext = $fulltext; 22 return $this; 23 } 24 25 public function execute() { 26 $table = new ConpherenceIndex(); 27 $conn_r = $table->establishConnection('r'); 28 29 $rows = queryfx_all( 30 $conn_r, 31 'SELECT threadPHID, transactionPHID, previousTransactionPHID 32 FROM %T i %Q %Q %Q', 33 $table->getTableName(), 34 $this->buildWhereClause($conn_r), 35 $this->buildOrderByClause($conn_r), 36 $this->buildLimitClause($conn_r)); 37 38 return $rows; 39 } 40 41 protected function buildWhereClause(AphrontDatabaseConnection $conn) { 42 $where = array(); 43 44 if ($this->threadPHIDs !== null) { 45 $where[] = qsprintf( 46 $conn, 47 'i.threadPHID IN (%Ls)', 48 $this->threadPHIDs); 49 } 50 51 if ($this->previousTransactionPHIDs !== null) { 52 $where[] = qsprintf( 53 $conn, 54 'i.previousTransactionPHID IN (%Ls)', 55 $this->previousTransactionPHIDs); 56 } 57 58 if (phutil_nonempty_string($this->fulltext)) { 59 $compiler = PhabricatorSearchDocument::newQueryCompiler(); 60 $tokens = $compiler->newTokens($this->fulltext); 61 $compiled_query = $compiler->compileQuery($tokens); 62 63 $where[] = qsprintf( 64 $conn, 65 'MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE)', 66 $compiled_query); 67 } 68 69 return $this->formatWhereClause($conn, $where); 70 } 71 72 private function buildOrderByClause(AphrontDatabaseConnection $conn_r) { 73 if (phutil_nonempty_string($this->fulltext)) { 74 return qsprintf( 75 $conn_r, 76 'ORDER BY MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE) DESC', 77 $this->fulltext); 78 } else { 79 return qsprintf( 80 $conn_r, 81 'ORDER BY id DESC'); 82 } 83 } 84 85}