Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / index / PhabricatorFulltextEngine.php
blobe1b2f4471d41e7ff4ca69b91c5c8cd2780f9ce77
1 <?php
3 abstract class PhabricatorFulltextEngine
4 extends Phobject {
6 private $object;
8 public function setObject($object) {
9 $this->object = $object;
10 return $this;
13 public function getObject() {
14 return $this->object;
17 protected function getViewer() {
18 return PhabricatorUser::getOmnipotentUser();
21 abstract protected function buildAbstractDocument(
22 PhabricatorSearchAbstractDocument $document,
23 $object);
25 final public function buildFulltextIndexes() {
26 $object = $this->getObject();
28 $extensions = PhabricatorFulltextEngineExtension::getAllExtensions();
30 $enrich_extensions = array();
31 $index_extensions = array();
32 foreach ($extensions as $key => $extension) {
33 if ($extension->shouldEnrichFulltextObject($object)) {
34 $enrich_extensions[] = $extension;
37 if ($extension->shouldIndexFulltextObject($object)) {
38 $index_extensions[] = $extension;
42 $document = $this->newAbstractDocument($object);
44 $this->buildAbstractDocument($document, $object);
46 foreach ($enrich_extensions as $extension) {
47 $extension->enrichFulltextObject($object, $document);
50 foreach ($index_extensions as $extension) {
51 $extension->indexFulltextObject($object, $document);
54 PhabricatorSearchService::reindexAbstractDocument($document);
57 protected function newAbstractDocument($object) {
58 $phid = $object->getPHID();
59 return id(new PhabricatorSearchAbstractDocument())
60 ->setPHID($phid)
61 ->setDocumentType(phid_get_type($phid));