diff --git a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php index ecdd4d6e64..f7ecf57ba6 100644 --- a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php +++ b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php @@ -1,93 +1,76 @@ loadDocumentByPHID($phid); $commit_data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 'commitID = %d', $commit->getID()); $date_created = $commit->getEpoch(); $commit_message = $commit_data->getCommitMessage(); $author_phid = $commit_data->getCommitDetail('authorPHID'); $repository = id(new PhabricatorRepositoryQuery()) ->setViewer($this->getViewer()) ->withIDs(array($commit->getRepositoryID())) ->executeOne(); if (!$repository) { throw new Exception('No such repository!'); } $title = 'r'.$repository->getCallsign().$commit->getCommitIdentifier(). ' '.$commit_data->getSummary(); $doc = new PhabricatorSearchAbstractDocument(); $doc->setPHID($commit->getPHID()); $doc->setDocumentType(PhabricatorRepositoryCommitPHIDType::TYPECONST); $doc->setDocumentCreated($date_created); $doc->setDocumentModified($date_created); $doc->setDocumentTitle($title); $doc->addField( PhabricatorSearchField::FIELD_BODY, $commit_message); if ($author_phid) { $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $author_phid, PhabricatorPeopleUserPHIDType::TYPECONST, $date_created); } $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $commit->getPHID(), PhabricatorEdgeConfig::TYPE_COMMIT_HAS_PROJECT); if ($project_phids) { foreach ($project_phids as $project_phid) { $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, $project_phid, PhabricatorProjectProjectPHIDType::TYPECONST, $date_created); } } $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), PhabricatorRepositoryRepositoryPHIDType::TYPECONST, $date_created); - $comments = PhabricatorAuditComment::loadComments( - $this->getViewer(), - $commit->getPHID()); - foreach ($comments as $comment) { - if (strlen($comment->getContent())) { - $doc->addField( - PhabricatorSearchField::FIELD_COMMENT, - $comment->getContent()); - } - } - - $inlines = PhabricatorAuditInlineComment::loadPublishedComments( - $this->getViewer(), - $commit->getPHID()); - foreach ($inlines as $inline) { - if (strlen($inline->getContent())) { - $doc->addField( - PhabricatorSearchField::FIELD_COMMENT, - $inline->getContent()); - } - } + $this->indexTransactions( + $doc, + new PhabricatorAuditTransactionQuery(), + array($commit->getPHID())); return $doc; } } diff --git a/src/applications/search/index/PhabricatorSearchDocumentIndexer.php b/src/applications/search/index/PhabricatorSearchDocumentIndexer.php index 1758f05416..fbecdc8213 100644 --- a/src/applications/search/index/PhabricatorSearchDocumentIndexer.php +++ b/src/applications/search/index/PhabricatorSearchDocumentIndexer.php @@ -1,156 +1,155 @@ getIndexableObject(); return (phid_get_type($phid) == phid_get_type($object->generatePHID())); } public function getIndexIterator() { $object = $this->getIndexableObject(); return new LiskMigrationIterator($object); } protected function loadDocumentByPHID($phid) { $object = id(new PhabricatorObjectQuery()) ->setViewer($this->getViewer()) ->withPHIDs(array($phid)) ->executeOne(); if (!$object) { throw new Exception("Unable to load object by phid '{$phid}'!"); } return $object; } public function indexDocumentByPHID($phid) { try { $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(); try { $engine->reindexAbstractDocument($document); } catch (Exception $ex) { $phid = $document->getPHID(); $class = get_class($engine); phlog("Unable to index document {$phid} with engine {$class}."); phlog($ex); } $this->dispatchDidUpdateIndexEvent($phid, $document); } catch (Exception $ex) { $class = get_class($this); phlog("Unable to build document {$phid} with indexer {$class}."); phlog($ex); } return $this; } protected function newDocument($phid) { return id(new PhabricatorSearchAbstractDocument()) ->setPHID($phid) ->setDocumentType(phid_get_type($phid)); } protected function indexSubscribers( PhabricatorSearchAbstractDocument $doc) { $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( $doc->getPHID()); $handles = id(new PhabricatorHandleQuery()) ->setViewer($this->getViewer()) ->withPHIDs($subscribers) ->execute(); foreach ($handles as $phid => $handle) { $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $doc->getDocumentModified()); // Bogus timestamp. } } protected function indexTransactions( PhabricatorSearchAbstractDocument $doc, PhabricatorApplicationTransactionQuery $query, array $phids) { $xactions = id(clone $query) ->setViewer($this->getViewer()) ->withObjectPHIDs($phids) - ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) ->execute(); foreach ($xactions as $xaction) { if (!$xaction->hasComment()) { continue; } $comment = $xaction->getComment(); $doc->addField( PhabricatorSearchField::FIELD_COMMENT, $comment->getContent()); } } protected function indexCustomFields( PhabricatorSearchAbstractDocument $document, PhabricatorCustomFieldInterface $object) { // Rebuild the ApplicationSearch indexes. These are internal and not part of // 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. $field_list = PhabricatorCustomField::getObjectFields( $object, PhabricatorCustomField::ROLE_DEFAULT); $field_list->setViewer($this->getViewer()); $field_list->readFieldsFromStorage($object); // Rebuild ApplicationSearch indexes. $field_list->rebuildIndexes($object); // Rebuild global search indexes. $field_list->updateAbstractDocument($document); } private function dispatchDidUpdateIndexEvent( $phid, PhabricatorSearchAbstractDocument $document) { $event = new PhabricatorEvent( PhabricatorEventType::TYPE_SEARCH_DIDUPDATEINDEX, array( 'phid' => $phid, 'object' => $this->loadDocumentByPHID($phid), 'document' => $document, )); $event->setUser($this->getViewer()); PhutilEventEngine::dispatchEvent($event); } }