Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/index/PhabricatorSearchDocumentIndexer.php
| Show All 31 Lines | protected function loadDocumentByPHID($phid) { | ||||
| } | } | ||||
| return $object; | return $object; | ||||
| } | } | ||||
| public function indexDocumentByPHID($phid) { | public function indexDocumentByPHID($phid) { | ||||
| try { | try { | ||||
| $document = $this->buildAbstractDocumentByPHID($phid); | $document = $this->buildAbstractDocumentByPHID($phid); | ||||
| $object = $this->loadDocumentByPHID($phid); | |||||
| // Automatically rebuild CustomField indexes if the object uses custom | |||||
| // fields. | |||||
| if ($object instanceof PhabricatorCustomFieldInterface) { | |||||
| $this->indexCustomFields($document, $object); | |||||
| } | |||||
| // Automatically rebuild subscriber indexes if the object is subscribable. | |||||
| if ($object instanceof PhabricatorSubscribableInterface) { | |||||
| $this->indexSubscribers($document); | |||||
| } | |||||
| $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); | $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); | ||||
| try { | try { | ||||
| $engine->reindexAbstractDocument($document); | $engine->reindexAbstractDocument($document); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $phid = $document->getPHID(); | $phid = $document->getPHID(); | ||||
| $class = get_class($engine); | $class = get_class($engine); | ||||
| phlog("Unable to index document {$phid} with engine {$class}."); | phlog("Unable to index document {$phid} with engine {$class}."); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
| $comment = $xaction->getComment(); | $comment = $xaction->getComment(); | ||||
| $doc->addField( | $doc->addField( | ||||
| PhabricatorSearchField::FIELD_COMMENT, | PhabricatorSearchField::FIELD_COMMENT, | ||||
| $comment->getContent()); | $comment->getContent()); | ||||
| } | } | ||||
| } | } | ||||
| protected function indexCustomFields( | protected function indexCustomFields( | ||||
| PhabricatorSearchAbstractDocument $doc, | PhabricatorSearchAbstractDocument $document, | ||||
| PhabricatorCustomFieldInterface $object) { | PhabricatorCustomFieldInterface $object) { | ||||
| // Rebuild the ApplicationSearch indexes. These are internal and not part of | // Rebuild the ApplicationSearch indexes. These are internal and not part of | ||||
| // the fulltext search, but putting them in this workflow allows users to | // the fulltext search, but putting them in this workflow allows users to | ||||
| // use the same tools to rebuild the indexes, which is easy to understand. | // use the same tools to rebuild the indexes, which is easy to understand. | ||||
| $field_list = PhabricatorCustomField::getObjectFields( | $field_list = PhabricatorCustomField::getObjectFields( | ||||
| $object, | $object, | ||||
| PhabricatorCustomField::ROLE_APPLICATIONSEARCH); | PhabricatorCustomField::ROLE_DEFAULT); | ||||
| $field_list->setViewer($this->getViewer()); | $field_list->setViewer($this->getViewer()); | ||||
| $field_list->readFieldsFromStorage($object); | $field_list->readFieldsFromStorage($object); | ||||
| // Rebuild ApplicationSearch indexes. | |||||
| $field_list->rebuildIndexes($object); | $field_list->rebuildIndexes($object); | ||||
| // We could also allow fields to provide fulltext content, and index it | // Rebuild global search indexes. | ||||
| // here on the document. No one has asked for this yet, though, and the | $field_list->updateAbstractDocument($document); | ||||
| // existing "search" key isn't a good fit to interpret to mean we should | |||||
| // index stuff here, since it can be set on a lot of fields which don't | |||||
| // contain anything resembling fulltext. | |||||
| } | } | ||||
| private function dispatchDidUpdateIndexEvent( | private function dispatchDidUpdateIndexEvent( | ||||
| $phid, | $phid, | ||||
| PhabricatorSearchAbstractDocument $document) { | PhabricatorSearchAbstractDocument $document) { | ||||
| $event = new PhabricatorEvent( | $event = new PhabricatorEvent( | ||||
| PhabricatorEventType::TYPE_SEARCH_DIDUPDATEINDEX, | PhabricatorEventType::TYPE_SEARCH_DIDUPDATEINDEX, | ||||
| Show All 10 Lines | |||||