3 final class PhabricatorFulltextIndexEngineExtension
4 extends PhabricatorIndexEngineExtension
{
6 const EXTENSIONKEY
= 'fulltext';
8 private $configurationVersion;
10 public function getExtensionName() {
11 return pht('Fulltext Engine');
14 public function getIndexVersion($object) {
17 // When "cluster.search" is reconfigured, new indexes which don't have any
18 // data yet may have been added. We err on the side of caution and assume
19 // that every document may need to be reindexed.
20 $version[] = $this->getConfigurationVersion();
22 if ($object instanceof PhabricatorApplicationTransactionInterface
) {
23 // If this is a normal object with transactions, we only need to
24 // reindex it if there are new transactions (or comment edits).
25 $version[] = $this->getTransactionVersion($object);
26 $version[] = $this->getCommentVersion($object);
33 return implode(':', $version);
36 public function shouldIndexObject($object) {
37 return ($object instanceof PhabricatorFulltextInterface
);
40 public function indexObject(
41 PhabricatorIndexEngine
$engine,
44 $engine = $object->newFulltextEngine();
49 $engine->setObject($object);
51 $engine->buildFulltextIndexes();
54 private function getTransactionVersion($object) {
55 $xaction = $object->getApplicationTransactionTemplate();
57 $xaction_row = queryfx_one(
58 $xaction->establishConnection('r'),
59 'SELECT id FROM %T WHERE objectPHID = %s
60 ORDER BY id DESC LIMIT 1',
61 $xaction->getTableName(),
67 return $xaction_row['id'];
70 private function getCommentVersion($object) {
71 $xaction = $object->getApplicationTransactionTemplate();
73 $comment = $xaction->getApplicationTransactionCommentObject();
78 $comment_row = queryfx_one(
79 $comment->establishConnection('r'),
80 'SELECT c.id FROM %T x JOIN %T c
81 ON x.phid = c.transactionPHID
82 WHERE x.objectPHID = %s
83 ORDER BY c.id DESC LIMIT 1',
84 $xaction->getTableName(),
85 $comment->getTableName(),
91 return $comment_row['id'];
94 private function getConfigurationVersion() {
95 if ($this->configurationVersion
=== null) {
96 $this->configurationVersion
= $this->newConfigurationVersion();
98 return $this->configurationVersion
;
101 private function newConfigurationVersion() {
103 'services' => PhabricatorEnv
::getEnvConfig('cluster.search'),
106 $json = phutil_json_encode($raw);
108 return PhabricatorHash
::digestForIndex($json);