diff --git a/src/applications/pholio/search/PholioSearchIndexer.php b/src/applications/pholio/search/PholioSearchIndexer.php index 2ca69100b1..f05465818d 100644 --- a/src/applications/pholio/search/PholioSearchIndexer.php +++ b/src/applications/pholio/search/PholioSearchIndexer.php @@ -12,12 +12,10 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer { protected function buildAbstractDocumentByPHID($phid) { $mock = $this->loadDocumentByPHID($phid); - $doc = new PhabricatorSearchAbstractDocument(); - $doc->setPHID($mock->getPHID()); - $doc->setDocumentType(phid_get_type($mock->getPHID())); - $doc->setDocumentTitle($mock->getName()); - $doc->setDocumentCreated($mock->getDateCreated()); - $doc->setDocumentModified($mock->getDateModified()); + $doc = $this->newDocument($phid) + ->setDocumentTitle($mock->getName()) + ->setDocumentCreated($mock->getDateCreated()) + ->setDocumentModified($mock->getDateModified()); $doc->addField( PhabricatorSearchField::FIELD_BODY, @@ -29,6 +27,11 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer { PhabricatorPeoplePHIDTypeUser::TYPECONST, $mock->getDateCreated()); + $this->indexTransactions( + $doc, + new PholioTransactionQuery(), + array($phid)); + return $doc; } } diff --git a/src/applications/ponder/editor/PonderQuestionEditor.php b/src/applications/ponder/editor/PonderQuestionEditor.php index b72dafba32..32caa7da81 100644 --- a/src/applications/ponder/editor/PonderQuestionEditor.php +++ b/src/applications/ponder/editor/PonderQuestionEditor.php @@ -153,6 +153,22 @@ final class PonderQuestionEditor return array($object->getAuthorPHID()); } + protected function supportsSearch() { + return true; + } + + protected function shouldImplyCC( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + case PonderQuestionTransaction::TYPE_ANSWERS: + return true; + } + + return parent::shouldImplyCC($object, $xaction); + } + // TODO: Mail support } diff --git a/src/applications/ponder/search/PonderSearchIndexer.php b/src/applications/ponder/search/PonderSearchIndexer.php index 49f69d662f..854d4fd9d7 100644 --- a/src/applications/ponder/search/PonderSearchIndexer.php +++ b/src/applications/ponder/search/PonderSearchIndexer.php @@ -10,14 +10,10 @@ final class PonderSearchIndexer protected function buildAbstractDocumentByPHID($phid) { $question = $this->loadDocumentByPHID($phid); - $question->attachRelated(); - - $doc = new PhabricatorSearchAbstractDocument(); - $doc->setPHID($question->getPHID()); - $doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST); - $doc->setDocumentTitle($question->getTitle()); - $doc->setDocumentCreated($question->getDateCreated()); - $doc->setDocumentModified($question->getDateModified()); + $doc = $this->newDocument($phid) + ->setDocumentTitle($question->getTitle()) + ->setDocumentCreated($question->getDateCreated()) + ->setDocumentModified($question->getDateModified()); $doc->addField( PhabricatorSearchField::FIELD_BODY, @@ -29,42 +25,28 @@ final class PonderSearchIndexer PhabricatorPeoplePHIDTypeUser::TYPECONST, $question->getDateCreated()); - $comments = $question->getComments(); - foreach ($comments as $curcomment) { - $doc->addField( - PhabricatorSearchField::FIELD_COMMENT, - $curcomment->getContent()); - } - - $answers = $question->getAnswers(); - foreach ($answers as $curanswer) { - if (strlen($curanswer->getContent())) { - $doc->addField( - PhabricatorSearchField::FIELD_COMMENT, - $curanswer->getContent()); - } - - $answer_comments = $curanswer->getComments(); - foreach ($answer_comments as $curcomment) { + $answers = id(new PonderAnswerQuery()) + ->setViewer($this->getViewer()) + ->withQuestionIDs(array($question->getID())) + ->execute(); + foreach ($answers as $answer) { + if (strlen($answer->getContent())) { $doc->addField( PhabricatorSearchField::FIELD_COMMENT, - $curcomment->getContent()); + $answer->getContent()); } } - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( - $question->getPHID()); - $handles = id(new PhabricatorObjectHandleData($subscribers)) - ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->loadHandles(); + $this->indexTransactions( + $doc, + new PonderQuestionTransactionQuery(), + array($phid)); + $this->indexTransactions( + $doc, + new PonderAnswerTransactionQuery(), + mpull($answers, 'getPHID')); - foreach ($handles as $phid => $handle) { - $doc->addRelationship( - PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, - $phid, - $handle->getType(), - $question->getDateModified()); // Bogus timestamp. - } + $this->indexSubscribers($doc); return $doc; } diff --git a/src/applications/search/index/PhabricatorSearchDocumentIndexer.php b/src/applications/search/index/PhabricatorSearchDocumentIndexer.php index e0fa8afe6d..b7fddf568c 100644 --- a/src/applications/search/index/PhabricatorSearchDocumentIndexer.php +++ b/src/applications/search/index/PhabricatorSearchDocumentIndexer.php @@ -8,6 +8,10 @@ abstract class PhabricatorSearchDocumentIndexer { abstract public function getIndexableObject(); abstract protected function buildAbstractDocumentByPHID($phid); + protected function getViewer() { + return PhabricatorUser::getOmnipotentUser(); + } + public function shouldIndexDocumentByPHID($phid) { $object = $this->getIndexableObject(); return (phid_get_type($phid) == phid_get_type($object->generatePHID())); @@ -19,12 +23,14 @@ abstract class PhabricatorSearchDocumentIndexer { } protected function loadDocumentByPHID($phid) { - $object = $this->getIndexableObject(); - $document = $object->loadOneWhere('phid = %s', $phid); - if (!$document) { - throw new Exception("Unable to load document by phid '{$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 $document; + return $object; } public function indexDocumentByPHID($phid) { @@ -51,4 +57,52 @@ abstract class PhabricatorSearchDocumentIndexer { 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()); + } + } + }