~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to phabricator/src/applications/conpherence/query/ConpherenceFulltextQuery.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-01-29 00:15:58 UTC
  • mfrom: (0.16.1) (0.15.1) (0.12.2) (2.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20150129001558-na84707j70qqla7z
Tags: 0~git20150129-1
* New snapshot release
* restricted access to local config file (closes: #775479)
* moved local config file to /var/lib/phabricator (closes: #775478)
* switched mysql-server dependency to recommends (closes: #773536)
* use /run instead of /var/run (closes: #775803)
* prevent package reinstall from overwritting local changes (closes: #776288)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class ConpherenceFulltextQuery
 
4
  extends PhabricatorOffsetPagedQuery {
 
5
 
 
6
  private $threadPHIDs;
 
7
  private $fulltext;
 
8
 
 
9
  public function withThreadPHIDs(array $phids) {
 
10
    $this->threadPHIDs = $phids;
 
11
    return $this;
 
12
  }
 
13
 
 
14
  public function withFulltext($fulltext) {
 
15
    $this->fulltext = $fulltext;
 
16
    return $this;
 
17
  }
 
18
 
 
19
  public function execute() {
 
20
    $table = new ConpherenceIndex();
 
21
    $conn_r = $table->establishConnection('r');
 
22
 
 
23
    $rows = queryfx_all(
 
24
      $conn_r,
 
25
      'SELECT threadPHID, transactionPHID, previousTransactionPHID
 
26
        FROM %T i %Q %Q %Q',
 
27
      $table->getTableName(),
 
28
      $this->buildWhereClause($conn_r),
 
29
      $this->buildOrderByClause($conn_r),
 
30
      $this->buildLimitClause($conn_r));
 
31
 
 
32
    return $rows;
 
33
  }
 
34
 
 
35
  private function buildWhereClause($conn_r) {
 
36
    $where = array();
 
37
 
 
38
    if ($this->threadPHIDs !== null) {
 
39
      $where[] = qsprintf(
 
40
        $conn_r,
 
41
        'i.threadPHID IN (%Ls)',
 
42
        $this->threadPHIDs);
 
43
    }
 
44
 
 
45
    if (strlen($this->fulltext)) {
 
46
      $where[] = qsprintf(
 
47
        $conn_r,
 
48
        'MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE)',
 
49
        $this->fulltext);
 
50
    }
 
51
 
 
52
    return $this->formatWhereClause($where);
 
53
  }
 
54
 
 
55
  private function buildOrderByClause(AphrontDatabaseConnection $conn_r) {
 
56
    if (strlen($this->fulltext)) {
 
57
      return qsprintf(
 
58
        $conn_r,
 
59
        'ORDER BY MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE) DESC',
 
60
        $this->fulltext);
 
61
    } else {
 
62
      return qsprintf(
 
63
        $conn_r,
 
64
        'ORDER BY id DESC');
 
65
    }
 
66
  }
 
67
 
 
68
}