Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / storage / document / PhabricatorSearchDocument.php
blob424a3ccd9bd0cf298162fc3ca7f1cea753e51057
1 <?php
3 final class PhabricatorSearchDocument extends PhabricatorSearchDAO {
5 protected $documentType;
6 protected $documentTitle;
7 protected $documentCreated;
8 protected $documentModified;
10 const STOPWORDS_TABLE = 'stopwords';
12 protected function getConfiguration() {
13 return array(
14 self::CONFIG_TIMESTAMPS => false,
15 self::CONFIG_IDS => self::IDS_MANUAL,
16 self::CONFIG_COLUMN_SCHEMA => array(
17 'documentType' => 'text4',
18 'documentTitle' => 'text255',
19 'documentCreated' => 'epoch',
20 'documentModified' => 'epoch',
22 self::CONFIG_KEY_SCHEMA => array(
23 'key_phid' => null,
24 'PRIMARY' => array(
25 'columns' => array('phid'),
26 'unique' => true,
28 'documentCreated' => array(
29 'columns' => array('documentCreated'),
31 'key_type' => array(
32 'columns' => array('documentType', 'documentCreated'),
35 ) + parent::getConfiguration();
38 public function getIDKey() {
39 return 'phid';
42 public static function newQueryCompiler() {
43 $compiler = new PhutilSearchQueryCompiler();
45 if (self::isInnoDBFulltextEngineAvailable()) {
46 // The InnoDB fulltext boolean operators are always the same as the
47 // default MyISAM operators, so we do not need to adjust the compiler.
48 } else {
49 $table = new self();
50 $conn = $table->establishConnection('r');
52 $operators = queryfx_one(
53 $conn,
54 'SELECT @@ft_boolean_syntax AS syntax');
55 if ($operators) {
56 $compiler->setOperators($operators['syntax']);
60 return $compiler;
63 public static function isInnoDBFulltextEngineAvailable() {
64 static $available;
66 if ($available === null) {
67 $table = new self();
68 $conn = $table->establishConnection('r');
70 // If this system variable exists, we can use InnoDB fulltext. If it
71 // does not, this query will throw and we're stuck with MyISAM.
72 try {
73 queryfx_one(
74 $conn,
75 'SELECT @@innodb_ft_max_token_size');
76 $available = true;
77 } catch (AphrontQueryException $x) {
78 $available = false;
82 return $available;